Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

LocalScript being a ServerScript? ( Easy fix )

Asked by
14dark14 167
4 years ago
Edited 4 years ago

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

Log in to vote
0
Answered by 4 years ago

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
Ad

Answer this question