local Target = game.ReplicatedStorage.NPC
local Script = game.ReplicatedStorage.NPC:WaitForChild("Script")
function onTouched(hit)
if game.Workspace.Value.Value == 1 then
Target.Parent = game.Workspace
Script.Disabled = false
wait(0.50)
Target.Parent = game.ReplicatedStorage
Script.Disabled = true
script.Disabled = true
wait()
end
end
script.Parent.Touched:connect(onTouched)
it freezes my testing window and says “Script timeout: exhausted allowed execution time” in the output, eventually it unfreezes 20 seconds later. Why is this happening and is there a simple way of fixing this?
local Target = game.ReplicatedStorage:WaitForChild("NPC")
local Script = Target:WaitForChild("Script")
function onTouched(hit)
if game.Workspace.Value.Value == 1 then
Target.Parent = game.Workspace
Script.Disabled = false
wait(0.50)
workspace:WaitForChild("NPC").Parent = game.ReplicatedStorage
workspace:WaitForChild("NPC"):WaitForChild("Script").Disabled = true
end
end
end
script.Parent.Touched:connect(onTouched)
@JigglyWiggles@static2240 Still not working, now It’s not giving me the error message for both your guy’s solutions but It’s not doing anything anymore.
debounce should be added because you need your NPC.Script to be enabled and disabled only once. This should work
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Target = ReplicatedStorage.NPC
local Script = ReplicatedStorage.NPC.Script
local debounce = false
function onTouched(hit)
if not debounce and workspace.Value.Value == 1 then
debounce = true
print("Touched only once")
Target.Parent = workspace
Script.Disabled = false
wait(0.50)
Target.Parent = ReplicatedStorage
Script.Disabled = true
script.Disabled = true
end
end
script.Parent.Touched:connect(onTouched)
What about the script you are trying to enable is there a loop inside that script ?
Roblox Lua scripts are extremely fast so fast that if you have a loop say:
while true do
print("This thing")
end
It will freeze studio for 10-20 seconds and you will see in the output that “This thing” was printed around 15 - 20 thousand times and you will have your error so your issue is most likely in the script your trying to enable
(Note: When working with loops always add a “wait(Amount of seconds”)