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)
I don't know.. Try adding
Delay = false
to the end so it'll loop?
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)
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.