player = script.Parent.Parent.Parent.Parent.Parent.Parent cost = 0 function checkForBat() found = false for i, v in pairs(player.Backpack.GetChildren()) do if v.Name == "Bat" then found = true end end for i, v in pairs(player.Character.GetChildren()) do if v.Name == "Bat" then found = true end end if found == true then return true else return false end end script.MouseButton1Click:connect(function() leaderstats = player.FindFirstChild("leaderstats") if leaderstats then Money = leaderstats.FindFirstchild("Money") if Money then hasBat = checkForBat() if Money.Value >= cost and hasBat == false then Money.Value = Money.Value - cost Bat = game.Lighting.Bat:Clone() Bat.Parent = player.Backpack end end end end)
Nothing happens. The GUI is working perfectly, the script just won't do anything....
** The place link is >http://www.roblox.com/The-Purge-place?id=158668406< if it'll help.**
player = game.Players.LocalPlayer --This only works in a local script. cost = 0 --assign the cost of the bat here. function checkForBat() local found = false for i, v in pairs(player.Backpack:GetChildren()) do if v.Name == "Bat" then found = true end end for i, v in pairs(player.Character:GetChildren()) do if v.Name == "Bat" then found = true end end return found end GuiButtonPath.MouseButton1Click:connect(function() local needsBat = not checkForBat() --needsBat is the opposite of found. leaderstats = player:FindFirstChild("leaderstats") if leaderstats ~= nil then Money = leaderstats:FindFirstchild("Money") if Money ~= nil then if Money.Value >= cost and needsBat then --if they have the money and they need a bat Money.Value = Money.Value - cost --subtract cost from funds Bat = game.Lighting.Bat:Clone() Bat.Parent = player.Backpack --give them a bat end end end end)
Okay, so I noticed that you are not actually using the Methods on the values you call, for instance:
Money = leaderstats.FindFirstchild("Money")
But FindFirstChild
is a method, you have to use colons not a period, that goes for the GetChildren
method too.