Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why isn't this delay working?

I have a delay in this script to stop it cloning the item hundreds of time, but it doesn't seem to work and I don't know why, instead it clones the item infinite times leading to my studio crashing:

local Character = script.Parent
local Humanoid = Character.Humanoid
local Torso = Character.Torso

local Delay = false

function OnDeath()
	if Delay == true then
		return;
	end
	Delay = true
	local ReplicatedStorage = game:GetService("ReplicatedStorage")
	local Body = ReplicatedStorage:WaitForChild(" ")
	local BodyClone = Body:Clone()
	Instance.new("Humanoid", BodyClone)
	BodyClone.Parent = game.Workspace
end

Humanoid.Died:connect(OnDeath)

3 comments

1

You never set the Delay to "true" anywhere in the script.

0

Does "Body" have a script inside it? The Body dies as soon as it is cloned into workspace, which triggers a script, etc...

0

Deleted my last comment. It was uncalled for.

4 answers

I don't know.. Try adding

Delay = false

to the end so it'll loop?

1 comment

1

You don't know? Why the hell are you answering the question..

Try this:

local Character = script.Parent
local Player = game.Players:GetPlayerFromCharacter(Character)
local Humanoid = Character.Humanoid
local Torso = Character.Torso

local Delay = false

function OnDeath()
    if not Delay then
    	Delay = true
    	local ReplicatedStorage = game:GetService("ReplicatedStorage")
	    local Body = ReplicatedStorage:WaitForChild(" ")
	    local BodyClone = Body:Clone()
	    Instance.new("Humanoid", BodyClone)
	    BodyClone.Parent = game.Workspace
    end
end

function onSpawn()
	Delay = false
end

Humanoid.Died:connect(OnDeath)
Player.CharacterAdded:connect(OnSpawn)

1 comment

0

Didn't work.

Where is the script located? Are you cloning this script in when a player spawns? if so, you're basically removing the script, and adding a new, fresh one (which has delay equal to false.)

First off why are you doing

local delay

if you want to delay something why not just do

wait(10) --or whatever other number you want to use.

3 comments

0

I think he was meaning to use it as a debounce.

0

Because the wait will only wait the function, and because it's a function it will occur still the same amount of times.

0

oh. Never used debounce so I wasn't sure

This discussion is preserved as it was. New answers, comments, and votes are closed.