#my script dont work

1 messages · Page 1 of 1 (latest)

distant frost
#

it should respawn a dummy
the script is located in a rig that is located in a folder that is located in server storage
function respawn()
dummy = script.Parent:Clone()
dummy.Parent = workspace
print("spawned")
end

function despawn()
print("despawned")
if dummy.Humanoid.Health >1 then
dummy:Destroy(1)
wait(10)
respawn()
end
end

while true do
wait(0.1)
if dummy then
despawn()
else
respawn()
end
end

#

@valid ember you popped up when i typed 7 so help me ig

uneven sluice
distant frost
#

but thanks

uneven sluice
#

its an event on the humanoid

distant frost
#

helpin a friend with a game

uneven sluice
#

you can also connect it to script.Parent.Removing but for now dont worry about that

#

it would clone twice

uneven sluice
distant frost
#

not spawning for some reason'

uneven sluice
#

on output

#

check

distant frost
uneven sluice
#

or f9

#

hm

distant frost
#

nope

uneven sluice
#

did it print "spawned"?

distant frost
#

nope

uneven sluice
#

ooh

#

could you send a video footage

distant frost
#

also, the script is located in a rig that is located in a folder that is located in server storage so maybe thats why

#

but idk

distant frost
uneven sluice
#

its supposed to respawn when it dies

distant frost
uneven sluice
#

oh

#

yeah

#

you didnt tell

#
script.Parent = workspace

function respawn()
    script.Parent:Clone().Parent = workspace
    script.Parent:Destroy()
    
    print("spawned")
end

script.Parent.Humanoid.Died:Connect(respawn)
#

or wait wait scratch that

#

no nvm

#

as long as the dummy isnt needed anymore on the folder

distant frost
distant frost
#

or am i suppoused to add that to the the script

uneven sluice
#

but ignore it

distant frost
#

alr

uneven sluice
#

you can just put the dummy on workspace

#

the problem is

distant frost
#

lemme attempt

#

alr

uneven sluice
#

you typed script.Parent.Humanoid.Died:Connect(respawn()) not script.Parent.Humanoid.Died:Connect(respawn)

#

it calls the function immediately, so its not connected to the died signal

#

theoratically that would clone and destroy the dummy multiple times, which would crash your game

#

but thats just a theory

distant frost
#

Ohh

distant frost
#

it says spawned

#

but the thing has no health

#

and i think i know why

#

when it clones it, it has no health

uneven sluice
#

it parented the script into the workspace, not the rig

distant frost
#

so it cloning it with no health

#

which i may be able to fix but probably not

uneven sluice
#

oh

#

rig

#

right

#
script.Parent.Parent = workspace
local toSpawn = script.Parent:Clone()

function respawn()
    toSpawn.Parent = workspace
    script.Parent:Destroy()
    
    print("spawned")
end

script.Parent.Humanoid.Died:Connect(respawn)

@distant frost

#

you store the rig before it dies

#

👍

distant frost
#

alr lemme test this

true ruinBOT
#

studio** You are now Level 2! **studio

uneven sluice
#

why would you need to put it there anyway

#

if its a dummy

mild matrix
#

its bad practice

distant frost
#

What else am I to do

mild matrix
#

while task.wait() do

distant frost
#

Oh

mild matrix
#

also wait() sucks use task.wait() instead

distant frost
#

I didnt know u could do that

distant frost
mild matrix
#

wait() is deprecated

distant frost
mild matrix
#

don't use it for new work

distant frost
#

Why tho

#

If it works the same

mild matrix
distant frost
#

Do tell

mild matrix
distant frost
mild matrix
# distant frost

task.wait() is the newer, better version of wait() in Roblox Studio.

quick difference:

  • task.wait()

    • more accurate timing
    • less delay / less laggy
    • recommended by roblox now
  • wait() ⚠️

    • older / legacy
    • can be inconsistent
    • may pause longer than expected

simple answer:

use task.wait() almost all the time.
wait() still works, but it’s outdated.

#

real

distant frost
#

IF IT LEGIT DOES NOT WORK

mild matrix
distant frost
mild matrix
distant frost
mild matrix
#

if they want to update one they have to update the second one too

#

now imagine this on a large scale

#

also maybe some people like the functionality of wait()