script.Parent.Touched:Connect(function(plr)
local pp = plr.leaderstats.Points
pp.Value = pp.Value + 1
end)
Parent is a part.
script.Parent.Touched:Connect(function(plr)
local pp = plr.leaderstats.Points
pp.Value = pp.Value + 1
end)
Parent is a part.
You can't get a player from a touched event, it only checks for the object that's touching the part (in which the touch event script is located in). And so because of this, you need to make use of GetPlayerFromCharacter()
This is the code with GetPlayerFromCharacter():
local Players = game:GetService("Players")
script.Parent.Touched:Connect(function(hit)
if hit then
local Humanoid = hit.Parent:FindFirstChild("Humanoid")
if Humanoid and Humanoid ~= nil then
local Player = Players:GetPlayerFromCharacter(hit.Parent)
local Points = Player.leaderstats.Points
Points.Value = Points.Value + 1
end
end
end)
This discussion is preserved as it was. New answers, comments, and votes are closed.