Here is what i tried
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 i,v in pairs(game.Players.GetChildren()) i, torso.CFrame.new = (0, 0, 0) end end end
here is my output
23:08:34.180 - Plugin_276879563.HE-MONEY.LocalScript:4: '<name>' expected near '(' 23:08:34.216 - Plugin_160457204.No Lag Script:7: 'end' expected (to close 'if' at line 6) near '<eof>' 23:08:34.578 - Workspace.True.Script:10: 'end' expected (to close 'function' at line 1) near '<eof>' 23:08:34.900 - Unable to find module for asset id 23:08:34.900 - Stack Begin 23:08:34.900 - Script 'Workspace.Kohl's Admin Infinite.Credit', Line 1 23:08:34.901 - Stack End 23:08:35.036 - Players.Player1.PlayerGui.Intermission.Backround.Time.Time Changer:12: 'do' expected near 'i'
At line 12, you forgot to add the word "do" (not a string) to the end of the for loop.
But don't bother with that one, here's another script that will be far more efficient and use far less processor power. NumberValues (Which I assume you're using) have an event called Changed, which fires whenever the value of it is changed. Consider the following:
local startime = script.Parent.Timee local substraction = - 1 --Note: I think you may have misspelled here, make sure you don't cause any errors this way. starttime.Changed:connect(function(val) --the Changed event provides val, the new value of the NumberValue, as an argument wait(0.1) if val > 0 then script.Parent.Text = startime.Value.. ' Seconds' wait(0.5) if val - 1 == 0 then --Note that I didn't actually subtract the value, I simply calculated what would happen if it were to be subtracted script.Parent.Text = 'Beginning' for i,v in pairs(game.Players.GetChildren()) do --Note my addition of do! --Each v is actually a player object, and not the player within the workspace. To get that, simply use v.Character v.Character.Torso.CFrame.new = (0, 0, 0) --I also fixed capitalization here - the t in Torso is upercase when it comes to characters! end end end)
If you need to subtract the NumberValue, you know what to do. Hope I could help!
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.
First of all you could do this a lot easier than what you are already doing by using a second for loop as shown
start_time = local startime = script.Parent.Timee wait(1) for i = start_time.Value, 1, -1 local starttime = i script.Parent.Text = starttime.Value.. 'Seconds' if starttime == 0 then script.Parent.Text = 'Beginning' for i,v in pairs(game.Players.GetChildren()) do if v.Character:FindFirstChild("Torso") then v.torso.CFrame = CFrame.new(0, 0, 0) end end end end