Hello everyone, Im currently coding a Point system, I made a part leading with a script inside of it to make the system work, Heres the code:
local PointGiver = script.Parent
local pointstoAdd = 10
local function onTouched(hit)
local player =
game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
player.leaderstats.Points.Value =
player.leaderstats.Points.Value + pointstoAdd
print(player.Name .. "earned" .. "Points!")
end
end
PointGiver.Touched:Connect(onTouched())
However I made the leaderstats aswell:
local leaderboard = script.Parent
local function updateLeaderboard()
local players =
game.Players:GetPlayers()
for i, player in ipairs(players)
do
local points =
player.Leaderstats.Points.Value
leaderboard["Player" ..
i].Text = player.Name .. ": " .. points
end
end
game.Players.PlayerAdded:Connect(updateLeaderboard)
for _, player in
ipairs(game.Players:GetPlayers()) do
player.leaderstats.Points:GetpropertyChangedSignal("Value"):Connect(updateLeaderboard())
end
local function onPlayerAdded(player)
local leaderstats =
Instance.new ("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local points =
Instance.new("IntValue")
points.Name = "Points"
points.Value = 0
points.Parent = leaderstats
end
game.Players.PlayerAdded:Connect(onPlayerAdded)
I don’t get any errors, But when I go to touch the part nothing happens.