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

I got this scrip to work in Roblox studio but when I join the game from Roblox it is't working?

Asked by 6 years ago

this is the script: part = script.Parent part.Touched:connect(function(hit) player = game:GetService("Players").LocalPlayer stats = player:findFirstChild("leaderstats") coins = stats:findFirstChild("Coins") coins.Value = coins.Value + 1
end)

and yes I have a leaderboard script

0
You can only use local player in a local script YouSNICKER 131 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

Whenever doing a touched function you can not use LocalPlayer as it only works in LocalScripts

This code here should work:

script.Parent.Touched:connect(function(part)
    if game.Players:FindFirstChild(part.Parent.Name) then
        local plr = game.Players:FindFirstChild(part.Parent.Name)
        plr.leaderstats.Coins.Value = plr.leaderstats.Coins.Value + 1
    end
end)
0
thanks ootheboss 32 — 6y
0
if it worked then click "Accept Answer" YouSNICKER 131 — 6y
Ad

Answer this question