I am making a tycoon, and the part that does not work is when the item touches the furnace, it gives you money. It works perfectly in studio but not in game. Can someone explain why? Thanks.
here is the script:
local Part = script.Parent Part.Touched:connect(function(hit) if hit.Name == "Shirt" then wait(1) hit:Destroy() game.Players.LocalPlayer.leaderstats.Cash.Value = game.Players.LocalPlayer.leaderstats.Cash.Value + 20 end end)
Your script doesn't work online because the script is running on the server which is also the client in Studio. To make it work for online games, change your code to the one below.
local Part = script.Parent Part.Touched:connect(function(hit) if hit.Parent then local player = game.Players:GetPlayerFromCharacter(hit.Parent); if player then player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + 20 end end end end)
Let me tell you how the script works.
It listens for a Touched event. If the event fires, it checks hit's Parent (the character) and then tries to get the player owning it.
If it returns the player, use that player and change the amount of cash to your desired value. If nil, just ignore the changing sequence and go back to step 1.