Hi there! I'm making a game where the players points update by one every second. Here's the original scrip, which is inside Serverscriptservice:
local Players = game:GetService("Players")
local UpdatePoints = false
Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Character)
UpdatePoints = true
local Leaderstats = Instance.new("Folder")
Leaderstats.Name = "leaderstats"
Leaderstats.Parent = Player
local Points = Instance.new("IntValue")
Points.Name = "Points"
Points.Parent = Leaderstats
Player.leaderstats.Points.Value = 0
local Humanoid = Character.Humanoid
Humanoid.Died:Connect(function()
UpdatePoints = false
Player.leaderstats.Points.Value = 0
end)
while (UpdatePoints) do
wait(1)
Player.leaderstats.Points.Value += 1
if not (UpdatePoints) then
break
end
end
end)
end)
This works fine. Then, I needed the points to start updating only when the player steps on a model, called "Game." So I added this:
local Players = game:GetService("Players")
local UpdatePoints = false
local function onTouch(part)
return end
end
part.Touched:Connect(onTouch)
Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Character)
UpdatePoints = true
local Leaderstats = Instance.new("Folder")
Leaderstats.Name = "leaderstats"
Leaderstats.Parent = Player
local Points = Instance.new("IntValue")
Points.Name = "Points"
Points.Parent = Leaderstats
Player.leaderstats.Points.Value = 0
local Humanoid = Character.Humanoid
Humanoid.Died:Connect(function()
UpdatePoints = false
Player.leaderstats.Points.Value = 0
end)
while (UpdatePoints) do
wait(1)
Player.leaderstats.Points.Value += 1
if not (UpdatePoints) then
break
end
end
end)
end)
But, this broke the script. Again, this script is in Serverscriptservice (or storage, maybe...) Can you help fix this?
