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 1 year 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?

local Part = script.Parent

local function hit()

    game.Players.LocalPlayer.leaderstats.Coins.Value = game.Players.LocalPlayer.leaderstats.Clicks.Value

end

Part.Touched:Connect(hit)

Thanks!

1 answer

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

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

local Part = script.Parent

local function onHit(Hit)
    local Players = game:GetService('Players')
    local Player = Players:GetPlayerFromCharacter(Hit.Parent)
    if Player then
        Player.leaderstats.Coins.Value = Player.leaderstats.Clicks.Value
    end
end

Part.Touched:Connect(onHit)
0
Nothing happened no error either kickoff127 103 — 1y
0
Nothing happened no error either kickoff127 103 — 1y
0
He means that this code should be a normal script inside the part. T3_MasterGamer 2189 — 1y
Ad

Answer this question