I am trying to make a currency pickup system.
When I were to touch the object, it should increase the leaderboard value for the player's coins via leaderstats, but it doesn't. I did not receive any error messages, so I am completely left in the dark.
The following code is in a local script.
coin = script.Parent coin.Touched:Connect(function(player) if coin.AlreadyCollected.Value == false then local LocalPlayer = game.Players.LocalPlayer local gold = LocalPlayer.leaderstats.Gold.Value gold = gold + 1 end end)
Any help will be appreciated! :)
Just a heads up that LocalScripts only affect that one person, or the client! I'll attempt to remake your script here;
--Script local coin = script.Parent coin.Touched:Connect(function(hit) --.Touched only returns the part that touched it, not the player local plr = game.Players:GetPlayerFromCharacter(hit.Parent) --Checks if the hit's parent is a character if plr and not coin.AlreadyCollected.Value then --If it is, and if the bool is false then coin.AlreadyCollected.Value = true --Makes it so it can't be collected again local gold = plr.leaderstats.Gold.Value gold = gold + 1 --Adds the gold end end)
Localscripts only affect the client, and don't even work in the workspace. Get the character using game.Players:GetPlayerFromCharacter(player.Parent), and then add it to the player's currency through that.