Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why isn't this delay working?

Asked by
iFlusters 355 Moderation Voter
8 years ago

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)
1
You never set the Delay to "true" anywhere in the script. XAXA 1569 — 8y
0
Does "Body" have a script inside it? The Body dies as soon as it is cloned into workspace, which triggers a script, etc... XAXA 1569 — 8y
0
Deleted my last comment. It was uncalled for. XAXA 1569 — 8y

4 answers

Log in to vote
0
Answered by 8 years ago

I don't know.. Try adding

Delay = false

to the end so it'll loop?

1
You don't know? Why the hell are you answering the question.. iFlusters 355 — 8y
Ad
Log in to vote
0
Answered by
Pyrondon 2089 Game Jam Winner Moderation Voter Community Moderator
8 years ago

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)
0
Didn't work. iFlusters 355 — 8y
Log in to vote
0
Answered by 8 years ago

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.)

Log in to vote
0
Answered by 8 years ago

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.
0
I think he was meaning to use it as a debounce. Pyrondon 2089 — 8y
0
Because the wait will only wait the function, and because it's a function it will occur still the same amount of times. iFlusters 355 — 8y
0
oh. Never used debounce so I wasn't sure Conmmander 479 — 8y

Answer this question