I was working on a game and created a script, but it’s not running. I’ve tried many different ways to make it run, but there are no errors and I’m not sure what I’ve done wrong. Here’s the script:
local Status = game.ReplicatedStorage.Values.Status
local inround = game.ReplicatedStorage.Values:WaitForChild("inround")
local SpawnMap = game.Workspace:WaitForChild("spawn")
local Map1 = game.ReplicatedStorage.maps:WaitForChild("map1")
local primarypart = Map1.PrimaryPart
function timer()
for i = 20, 1, -1 do
inround.Value = false
Status.Value = "Starting in: "..i
wait(1)
end
end
function ingame()
local player = game.Players:GetPlayers()
for i, v in pairs(player) do
if v.Character ~= nil then
v.Character.Humanoid.HumanoidRootPart:MoveTo(primarypart.CFrame)
end
end
end
function ingametimer()
for i = 50, 1, -1 do
inround.Value = true
Status.Value = "Inround: "..i
wait(1)
end
end
for i, v in pairs(game.Players:GetPlayers()) do
if v.Character ~= nil then
while true do
timer()
wait()
ingame()
wait()
ingametimer()
end
end
end
I tested the script and didn’t find any errors, but it still won’t run. I’m not sure what the issue is, but I suspect it could be related to the function. Other scripts are working properly, but this one isn’t.
Your issue is with your usage of the for instance. It is playing an infinite version of the loop.
v.Character.Humanoid.HumanoidRootPart should work as just v.Character.HumanoidRootPart
local Status = game.ReplicatedStorage.Values.Status
local inround = game.ReplicatedStorage.Values:WaitForChild("inround")
local SpawnMap = game.Workspace:WaitForChild("spawn")
local Map1 = game.ReplicatedStorage.maps:WaitForChild("map1")
local primarypart = Map1.PrimaryPart
function timer()
for i = 20, 1, -1 do
inround.Value = false
Status.Value = "Starting in: "..i
wait(1)
end
end
function ingame()
local player = game.Players:GetPlayers()
for i, v in pairs(player) do
if v.Character ~= nil then
v.Character.HumanoidRootPart.CFrame = primarypart.CFrame
end
end
end
function ingametimer()
for i = 50, 1, -1 do
inround.Value = true
Status.Value = "Inround: "..i
wait(1)
end
end
while true do
timer()
wait()
ingame()
wait()
ingametimer()
end