Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

LocalScript being a ServerScript? ( Easy fix )

I have this coin script that will give player 10 coins when he collects a coin on the map. The problem is when the player collects the coin it gives every player in the game 10 coins and the coin disappears on all player's screen.

So far I have only 1 coin in the game for testing purposes I will make a different script later, but for now I need to understand how to give the player who collected the coin 10+ coins and make it only disappear on his screen.

LocalScript Inside StarterGui

local coin = game.Workspace.CoinGet         -- Coin Part 
local cash = script.Parent.Parent.ScreenGui.Cash      
coin.Touched:Connect(function()
	cash.Value = cash.Value + 10 -- Gives all players 10 coins.
	coin:Destroy()  -- Destroys for all players.
end)

1 answer

When you run the game the game has a cash value and the player has a copy of it. I think what you did was made it so when the player touched the part, the game's cash value changed and you set everyone's coins to the game's value. To change the player's cash value add

local player = game.Players.LocalPlayer

and inside the touched function before you increase the value add

local cash = player.PlayerGui.Cash

This discussion is preserved as it was. New answers, comments, and votes are closed.