✓ Accepted answer
GENERAL PRACTICE
Your script will only work for your player, so you will want to define the player through the Player Event :GetPlayerFromCharacter() --- The player's character will be the hit.Parent
Your wait time can go into the function, rather than requiring a for-loop
ISSUES
You need a debounce to make sure the .Touched Event doesn't keep firing every time the part is touched (causing rapid gains after 5 seconds)
REVISED SERVER SCRIPT
local debounce = true
workspace.points.Touched:Connect(function(hit)
if debounce == false then return end
debounce = false
local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
local points = player:WaitForChild("leaderstats"):WaitForChild("points")
points.Value = points.Value + 100
wait(5)
debounce = true
end)
If you want the player to only ever receive the bonus once, you can just not reset the debounce
local debounce = true
workspace.points.Touched:Connect(function(hit)
if debounce == false then return end
debounce = false
local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
local points = player:WaitForChild("leaderstats"):WaitForChild("points")
points.Value = points.Value + 100
wait(5)
end)
2 comments
This only works for a user named "walvie" and not other players
I know, that's what they posted. I'm just assuming they're experimenting early on in their Lua learning and don't want to throw a truck-load of information.