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

Why wont anything happen with this leaderstat?

Asked by 2 years ago

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?

1local Part = script.Parent
2 
3local function hit()
4 
5    game.Players.LocalPlayer.leaderstats.Coins.Value = game.Players.LocalPlayer.leaderstats.Clicks.Value
6 
7end
8 
9Part.Touched:Connect(hit)

Thanks!

1 answer

Log in to vote
2
Answered by
pwx 1581 Moderation Voter
2 years ago

Because you're doing it on the client (LocalScript), it's ideal that the leaderstats are handled by the server (Script).

01local Part = script.Parent
02 
03local 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
09end
10 
11Part.Touched:Connect(onHit)
0
Nothing happened no error either kickoff127 103 — 2y
0
Nothing happened no error either kickoff127 103 — 2y
0
He means that this code should be a normal script inside the part. T3_MasterGamer 2189 — 2y
Ad

Answer this question