|
| 12 May 2013 09:41 AM |
I'm attempting to make a Loadout GUI using BoolValues stored in player, every time I seem to click on the text button, I get an error, and it disconnects.
sp = script.Parent
function equip(player, click) if player:FindFirstChild("SI61B").Value==true then player:FindFirstChild("Primary").Value = "SI61B" else sp.Text = "Weapon not owned" wait(1) sp.Text = "" wait(1) sp.Text = "Weapon not owned" wait(1) sp.Name = sp.Primary.Value end end
script.Parent.MouseButton1Click:connect(player, click)
What am I doing wrong? Should just say, I am slightly new to this, but I have a vague idea of what I'm doing. |
|
|
| Report Abuse |
|
|
| |
|
| |
|
|
| 12 May 2013 10:22 AM |
> if player:FindFirstChild("SI61B").Value==true then
--Try it without the .Value==true --Implying you want to check if the object exists.
if player:FindFirstChild("SI61B") then |
|
|
| Report Abuse |
|
|
|
| 12 May 2013 10:24 AM |
| I should have said this in my first post - You need to buy the weapons from a store before you can use them on your loadout, and that's where checking for the BoolValue being true comes in. |
|
|
| Report Abuse |
|
|
|
| 12 May 2013 10:29 AM |
function equip(player, click) if player:FindFirstChild("SI61B").Value==true then player:FindFirstChild("Primary").Value = "SI61B" else sp.Text = "Weapon not owned" wait(1) sp.Text = "" wait(1) sp.Text = "Weapon not owned" wait(1) sp.Name = sp.Primary.Value end end
Make sure this is correct?: -There are boolean values put into the character when they enter the game with the names of each weapon and also a string value called Primary placed in the player.
-sp is either a TextLabel or TextButton -There is also a value in sp called Primary
Might be the problem: Early in the script, you have:
player:FindFirstChild("Primary")
and later on you have
sp.Primary.Value |
|
|
| Report Abuse |
|
|
|
| 12 May 2013 10:31 AM |
| There's another StringValue in the text button with the weapon's name on it, it's because there's multiple pages. I'll try that out quickly. |
|
|
| Report Abuse |
|
|
|
| 12 May 2013 10:34 AM |
I'm going to log off of ROBLOX so I can't help you beyond this point. One final note.
Make sure that your locations are correct.
You said the values are in the text button, but your script is searching in the player. |
|
|
| Report Abuse |
|
|
|
| 12 May 2013 10:35 AM |
There's two 'Primary' values. One in the player, one in the button.
If this helps, here's the output after I click it...: 16:34:19.451 - attempt to call a nil value 16:34:19.453 - Disconnected event because of exception |
|
|
| Report Abuse |
|
|
| |
|
|
| 12 May 2013 11:01 AM |
I don't think that the event you're using, gives any arguments.
|
|
|
| Report Abuse |
|
|
|
| 12 May 2013 11:19 AM |
| Still can't get it to work. |
|
|
| Report Abuse |
|
|
|
| 12 May 2013 11:24 AM |
script.Parent.MouseButton1Click:connect(equip) Define player and click manually. |
|
|
| Report Abuse |
|
|
|
| 12 May 2013 11:40 AM |
I've changed it to this; local player = game.Players.LocalPlayer script.Parent.MouseButton1Click:connect(function (player, click) function equip(player, click) local gun1 = player:FindFirstChild("SI61B") local primary1 = player:FindFirstChild("Primary") if gun1.Value==true then primary1.Value = "SI61B" else if gun1.Value==false then script.Parent.Text = "Weapon not owned" wait(1) script.Parent.Text = "" wait(1) script.Parent.Text = "Weapon not owned" wait(1) script.Parent.Name = script.Parent.Primary.Value end end end end)
It's stopped erroring, but I'm getting nothing back. Like, it won't change the 'Primary' value to SI61B, nor will the GUI flash 'Weapon not owned'. |
|
|
| Report Abuse |
|
|
|
| 12 May 2013 11:42 AM |
local player = game.Players.LocalPlayer script.Parent.MouseButton1Click:connect(function() local gun1 = player:FindFirstChild("SI61B") local primary1 = player:FindFirstChild("Primary") if gun1.Value==true then primary1.Value = "SI61B" elseif gun1.Value==false then script.Parent.Text = "Weapon not owned" wait(1) script.Parent.Text = "" wait(1) script.Parent.Text = "Weapon not owned" wait(1) script.Parent.Name = script.Parent.Primary.Value end end) |
|
|
| Report Abuse |
|
|
|
| 12 May 2013 12:46 PM |
Awesome, works good now. Only problem is the last bit, (script.Parent.Name = script.Parent.Primary.Value) it's just staying as 'Weapon not owned', but that doesn't matter. I'll find a way around it. Cheers! |
|
|
| Report Abuse |
|
|