0

# My updating variable every second script doesn't work, can you help?

Edited 14 days ago

Hi there! I'm making a game where the players' points update by one every second. I need the points to start updating only when the player steps on a model, called "Game." Here is my script, which doesn't work. I hvae tried many times to fix this, but all attempts were unsuccessfull. (I would have added those attempts, but I delete them XD) Can you help me?

local Players = game:GetService("Players")
local UpdatePoints = false
local function onTouch(part)
return end
end
part.Touched:Connect(onTouch)
UpdatePoints = true

local Points = Instance.new("IntValue")
Points.Name = "Points"

local Humanoid = Character.Humanoid
Humanoid.Died:Connect(function()
UpdatePoints = false
end)

while (UpdatePoints) do
wait(1)
if not (UpdatePoints) then
break
end
end
end)
end)


Also, where would I put this script, if you can fix it. Thank you!

0
first of all, format your script!! i cant read this 0hsa 119 — 14d

0
NotedAPI 809
14 days ago
Edited 14 days ago

Hey Pug,

I saw a few things wrong with your script and I think fixed all the issues you were having. First, I moved the variable inside of the PlayerAdded event, because I think you only wanted to change the player's points depending on their variable bool value. Second, I moved the creation of stats outside of the CharacterAdded event as that will just add more and more leaderstats folders as they die or whenever it's added. Although, I did keep the HumanoidDied event inside of there.

local Players = game:GetService("Players")

--[[
local function onTouch(part)
return
end

part.Touched:Connect(onTouch)]]

local UpdatePoints = true

local Points = Instance.new("IntValue")
Points.Name = "Points"
Points.Value = 0

character.Humanoid.Died:Connect(function()
UpdatePoints = false
Points.Value = 0
end)
end)

while wait(1) do
if (UpdatePoints) then
Points.Value += 1
end
end
end)

0
Where do I put this? pugguy1000 3 — 12d