This isn't working and I'd like to know why. This script is supposed to function to where, when a gui is clicked, you buy color for a brick. I'm not sure what the problem is, please help me. Edit: Would someone please help?
local stats = Instance.new("IntValue") stats.Name = "leaderstats" local cash = Instance.new("IntValue") moneyToGive = -60 print "line 5" function onclick() if cash.Value < 60 then script.Sound2:Play() end if cash.Value >= 60 then cash.Value = cash.Value + moneyToGive script.Sound:Play() print "line 14" game.Workspace.Desperado.Body.BD.BrickColor = BrickColor.new("Storm blue") game.Workspace.Desperado.Body.TailG.BrickColor = BrickColor.new("Storm blue") end end script.Parent.MouseButton1Click:connect(onclick)
Problems: - how does this bold thing work?(edit: oh.) The leaderstats you were trying to create were not going into the player. Also, some minor bugs and you said something about when a GUI is clicked but used BrickColor. Try using Color3. And I have no idea what is going on with the adding -60 cash to a player but okay. And let me know if it doesn't work.
game.Players.PlayerAdded:Connect(function(Player) local leaderstats = Instance.new("Folder",Player) leaderstats.Name = "leaderstats" local Cash = Instance.new("IntValue") Cash.Name = "Cash" Cash.Value = 0 end) moneyToGive = -60 -- moneyToGive -60 lol moneyToTake -60 print("Line 2") local Player = game.Players.LocalPlayer local cash = "Cash" script.Parent.MouseButton1Click:Connect(function() -- MouseButton1Click only works for GUI buttons. if Player.leaderstats ~= nil then if Player.leaderstats[cash].Value < 60 then script.Sound2:Play() else if Player.leaderstats[cash].Value >= 60 then Player.leaderstats[cash].Value = Player.leaderstats[cash].Value + moneyToGive -- moneyToGive - 60? so if current cash i 100 then adding - 60 will ??? 40? script.Sound:Play() game.Workspace.Desperado.Body.BD.BrickColor = BrickColor.new("Storm blue") game.Workspace.Desperado.Body.TailG.BrickColor = BrickColor.new("Storm blue") end end end end)