So im making a game and for some reason changing this bool value is breaking my script(line 3)
The error is from line 7 however when I remove line 3 it works( Script timeout: exhausted allowed execution time)
Thanks in advance
local Players = game:GetService("Players")
local GameStartedValue = game.Workspace.GameStarted
local RS, SS = game:GetService("ReplicatedStorage"), game:GetService("ServerStorage")
local function gamestart()
if game.Workspace.GameStarted.Value == false then
GameStartedValue.Value = true
for keyvalue, player in pairs(Players:GetPlayers()) do
local num = math.random(1,5)
if workspace.Seats:FindFirstChild(num).Value.Value == "None" then
workspace.Seats:FindFirstChild(num).Value.Value = player.Name
workspace.Seats:FindFirstChild(num):Sit(player.Character.Humanoid)
local PlayerNumberSeat = Instance.new("NumberValue")
PlayerNumberSeat.Value = num
PlayerNumberSeat.Parent = player.Character
player.Character:FindFirstChild("PlayerInGame").Value = true
end
end
end
end
local function PlayerCountChecker()
if #Players:GetPlayers() > 0 then
RS.Intermisson:FireAllClients()
task.delay(12, gamestart)
else
RS.NotEnoughPlayers:FireAllClients(1)
end
end
Players.PlayerAdded:Connect(PlayerCountChecker)
Players.PlayerRemoving:Connect(PlayerCountChecker)
workspace.GameStarted.Changed:Connect(function()
if workspace.GameStarted.Value == true then
local RandomPlayer = Players:GetPlayers()[math.random(#Players:GetPlayers())]
repeat until RandomPlayer.Character:WaitForChild("PlayerInGame").Value == true
if RandomPlayer.Character:WaitForChild("PlayerInGame").Value == true then
RS.PickPlayer:FireClient(RandomPlayer)
local RandomPlayerWork = workspace:FindFirstChild(RandomPlayer.Name)
local WeaponAim = SS.LocalLookingAroundScript:Clone()
WeaponAim.Disabled = false
WeaponAim.Parent = RandomPlayerWork
print(RandomPlayer.Name)
local Deagle = SS.Deagle:Clone()
Deagle.Parent = RandomPlayerWork
RS.PickPlayer:FireClient(RandomPlayer)
wait(2)
------------------------------------------------------------------------------------------------------------
RS.PickPlayer.OnServerEvent:Connect(function()
local SeatNumber = RandomPlayerWork.Value.Value + 1
local playerSeat = workspace.Seats:FindFirstChild(SeatNumber)
repeat until playerSeat.Occupant ~= nil
if playerSeat.Occupant ~= nil then
local playerName = playerSeat.Value.Value
local Nextplayer = workspace:FindFirstChild(playerName)
local WeaponAim = SS.LocalLookingAroundScript:Clone()
WeaponAim.Disabled = false
WeaponAim.Parent = Nextplayer
print(RandomPlayer.Name)
Deagle.Parent = Nextplayer
RS.Fire.OnServerEvent:Connect(function()
local bullet = game.ServerStorage.Bullet:Clone()
bullet.Parent = game.Workspace
bullet.Position = Deagle.ShootPoint
bullet.Orientation = Deagle.ShootPoint
bullet.Touched:Connect(function(hit)
hit.Parent:FindFirstChild("Humanoid").Health = hit.Parent:FindFirstChild("Humanoid") - math.random(99,100)
bullet:Destroy()
print("Yes3")
end)
end)
end
end)
end
end
end)