There are a couple of problems with this. The obvious ones being the missing do and the incorrect syntax of your attempt to teleport the player. These can be easily remedied:
local startime = script.Parent.Timee
local substraction = - 1
while true do
wait(0.1)
if startime.Value > 0 then
script.Parent.Text = startime.Value.. ' Seconds'
wait(0.5)
startime.Value = startime.Value - 1
if startime.Value == 0 then
script.Parent.Text = 'Beginning'
for _,v in pairs(game.Players.GetChildren()) do
v.Character.Torso.CFrame = CFrame.new(0, 0, 0)
end;
end
end
end
Also, using a while loop here isn't good; once it reaches 0, it'll keep running without actually doing anything other than waiting for one tenth of a second. You should use a for loop, instead:
local startime = script.Parent.Timee
local substraction = - 1
for _ = startime.Value, 1, -1 do
wait(0.1)
if startime.Value > 0 then
script.Parent.Text = startime.Value.. ' Seconds'
wait(0.5)
startime.Value = startime.Value - 1
if startime.Value == 0 then
script.Parent.Text = 'Beginning'
for _,v in pairs(game.Players.GetChildren()) do
v.Character.Torso.CFrame = CFrame.new(0, 0, 0)
end;
end
end
end
While this code should work fine, it can be improved upon. Your substraction variable on line 2 is never used; might as well just remove that entirely. Also, you'll want to check if Character.Torso exists (better safe than sorry).
Since you're using a for loop now, you can remove the if statement if startime.Value > 0, as this will always be true.
You may want to add a Changed event too, in order to run this code whenever the value is updated:
local connection, update;
local startime = script.Parent.Timee
update = function()
connection:Disconnect();
for _ = startime.Value, 1, -1 do
wait(0.1)
script.Parent.Text = startime.Value.. ' Seconds'
wait(0.5)
startime.Value = startime.Value - 1
if startime.Value == 0 then
script.Parent.Text = 'Beginning'
for _,v in pairs(game.Players.GetChildren()) do
if v.Character:FindFirstChild('Torso') then
v.Character.Torso.CFrame = CFrame.new(0, 0, 0)
end;
end;
end;
end
connection = startime.Changed:Connect(update);
end
connection = startime.Changed:Connect(update);
update();
Hope this helped!
Read more about functions, signals, for loops, generic for loops, and FindFirstChild.
2 comments
I fixed your tabbing and put the output in a Codeblock.
put do after your for i, v in pairs statement first