I tried to make a script where when they touch a part, the number of clicks they had turned into the number of coins they have. Can someone tell me why this script does not work?
1 | local Part = script.Parent |
2 |
3 | local function hit() |
4 |
5 | game.Players.LocalPlayer.leaderstats.Coins.Value = game.Players.LocalPlayer.leaderstats.Clicks.Value |
6 |
7 | end |
8 |
9 | Part.Touched:Connect(hit) |
Thanks!
Because you're doing it on the client (LocalScript), it's ideal that the leaderstats are handled by the server (Script).
01 | local Part = script.Parent |
02 |
03 | local function onHit(Hit) |
04 | local Players = game:GetService( 'Players' ) |
05 | local Player = Players:GetPlayerFromCharacter(Hit.Parent) |
06 | if Player then |
07 | Player.leaderstats.Coins.Value = Player.leaderstats.Clicks.Value |
08 | end |
09 | end |
10 |
11 | Part.Touched:Connect(onHit) |