Hello, i made a system of pickup and the script crashes with the bug ‘script timeout exhausted allowed execution time’
Here’s the script:
for _, Pickup in pairs(Map:FindFirstChild("Pickup"):GetChildren()) do
local TouchedPlayers = {}
Pickup.Touched:Connect(function(Hit)
if Hit.Parent:FindFirstChildOfClass("Humanoid") then
local Player = game:GetService("Players"):GetPlayerFromCharacter(Hit.Parent)
if Player then
if Player.Team == game.Teams.Lobby then return end
if table.find(TouchedPlayers, Player) then return end
table.insert(TouchedPlayers, Player)
-- script
end
end
end)
wait(0.1)
end
This is caused when the script takes an exceedingly long amount of time to load. It normally happens when you have a loop with no wait and no soon ending
Hardcoding is when you already have values set instead of figuring them out, for instance instead of doing value = 3 + 7 * 4 you would do value = 31 you can’t always do this though
Yeah no Wait() usualy crashes. You are probably making a ton of Connects, which never get resolved.
put a Print at every-other line, and you will def find your error.
This is blatantly untrue. The break keyword exists for a reason. @MagicalAnteater , include the following to make sure your script doesn’t timeout:
local clock = os.clock()
for _, Pickup in pairs(Map:FindFirstChild("Pickup"):GetChildren()) do
local TouchedPlayers = {}
if os.clock() - clock => 0.1 then
wait(.1)
clock = os.clock()
end
Pickup.Touched:Connect(function(Hit)
if Hit.Parent:FindFirstChildOfClass("Humanoid") then
local Player = game:GetService("Players"):GetPlayerFromCharacter(Hit.Parent)
if Player and (Player.Team == game.Teams.Lobby or table.find(TouchedPlayers, Player)) then
table.insert(TouchedPlayers, Player)
-- script
end
end
end)
end