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

Why doesn't it give the player a point when they touch the part?

Asked by 4 years ago

Here is my script:~~~~~~~~~~~~~~~~~ player = game.Players.LocalPlayer

script.Parent.Touched:Connect(function(hit)

if player.hit then

    player.leaderstats.points.Value = points.Value + 1
end

end)




And then my LeaderBoard script~~~~~~~~~~~~~~~~~ game.Players.PlayerAdded:Connect(function(player) stats = Instance.new("IntValue",player) stats.Name = "leaderstats" points = Instance.new("IntValue",stats) points.Name = "Points" end)

1 answer

Log in to vote
0
Answered by
Prestory 1395 Moderation Voter
4 years ago
Edited 4 years ago

Localscript's do not work when parented to the workspace or a part that is inside the workspace instead use a server script not a local script and place this code inside it and parent it to the part

function Touch (hit)
    if hit.Parent:FindFirstChild('Humanoid') then
        local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
        local leaderstats = Player:WaitForChild('leaderstats')
        local Points = leaderstats:WaitForChild('Points')
        Points.Value = Points.Value + 1
    end
end

script.Parent.Touched:Connect(Touch)
0
I would recommend using remote events for this, to prevent hackers.(Depending on what your doing) BashGuy10 384 — 4y
0
Your completely wrong bad suggestion Prestory 1395 — 4y
0
that was rude ;( Ziruken 139 — 4y
0
But its true Prestory 1395 — 4y
Ad

Answer this question