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

Is it possible to change an intvalue's value locally on touch?

Asked by 4 years ago
Edited 4 years ago

I am having trouble with getting this to work. I tried a remote event, but it gave all players +1

local part = Instance.new("Part");
part.Parent = workspace;
part.CFrame = CFrame.new(-685.327, 150.022, 163.614);

local enabled = false;
part.Touched:connect(function(hit)
    if game.Players:FindFirstChild(hit.Parent.Name) and game.Players[hit.Parent.Name] == game.Players.LocalPlayer then
        enabled = true;
        wait(0.2);
        part:Destroy();
        hit.Parent.leaderstats.Stars.Value = hit.Parent.leaderstats.Stars.Value+1
        wait(0.3);
        enabled = false;
    end
end)

why

0
It must be server sided because leaderstats are server based CreationNation1 459 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

I used GetPlayerFromCharacter to be able to access leaderstats, it gets the player from who ever touched the part, and then it adds 1 to stars value, then it destroys the part.

part.Touched:connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
        plr.leaderstats.Stars.Value = plr.leaderstats.Stars.Value + 1
        part:Destroy()
    end
end)
Ad

Answer this question