This is supposed to add money to the money int value in the leaderstats when it touched the brick at the end of my tycoon thingy. It was working, but not anymore? Any ideas?
game.Players.PlayerAdded:connect(function(player) local leaderstats = Instance.new("Model",player) leaderstats.Name = "leaderstats" local money = Instance.new("IntValue", leaderstats) money.Name = "Money" money.Value = 0 function addMoney(b) if b.Name == "MONEYBRICK" then money.Value = money.Value + 5 if game.Workspace.UPGRADE1.Touched and b.Name == "MONEYBRICK" then money.Value = money.Value + 5 end end end function buyupgrade1() if money.Value >= 50 then money.Value = money.Value - 50 c = game.Lighting.UPGRADE1:Clone() wait(.5) c.Parent = game.Workspace game.Workspace.pp:Destroy() c.Transparency = 0.7 wait(1) c.Transparency = 0.5 wait(1) c.Transparency = 0.3 wait(1) c.Transparency = 0 end end end) game.Workspace.pp.Touched:connect(buyupgrade1) game.Workspace.HITPART.Touched:connect(addMoney)
Try this. If it works, I'll explain it.
game.Players.PlayerAdded:connect(function(player) local leaderstats = Instance.new("IntValue",player) leaderstats.Name = "leaderstats" local money = Instance.new("IntValue", leaderstats) money.Name = "Money" money.Value = 0 end) function addMoney(b) if b.Name == "MONEYBRICK" then --Is "b" a nil variable money.Value = money.Value + 5 if game.Workspace.UPGRADE1.Touched and b.Name == "MONEYBRICK" then money.Value = money.Value + 5 end end end function buyupgrade1() if money.Value >= 50 then money.Value = money.Value - 50 local c = game.Lighting.UPGRADE1:Clone() wait(.5) c.Parent = game.Workspace game.Workspace.pp:Destroy() c.Transparency = 0.7 wait(1) c.Transparency = 0.5 wait(1) c.Transparency = 0.3 wait(1) c.Transparency = 0 end end game.Workspace.pp.Touched:connect(buyupgrade1) game.Workspace.HITPART.Touched:connect(addMoney)
Thanks for everyones reponses, I got the problem fixed by removing some of the code from the main function. Lots of lessons learned here :P