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

Do I use WaitForChild or did I do something wrong?

https://scriptinghelpers.org/blog/it-works-in-studio-but-not-online -- I read this and I am still having a hard time.

It works in studio but not online. There are no errors in the output.

function JustWelding (character)
    local head = character.Head
    local torso = character.Torso
    script.Parent.CFrame = head.CFrame * CFrame.new(0,0,-5)
    local weld = Instance.new("Weld")
    weld.Part0 = torso
    weld.C0 = torso.CFrame:inverse()
    weld.Part1 = script.Parent
    weld.C1 = script.Parent.CFrame:inverse()
    wait() 
    weld.Parent = script.Parent
    script.Parent.Anchored = false
end

game.Players.PlayerAdded:connect(function(player)
    player.CharacterAdded:connect(JustWelding)
end)

I tried to use WaitForChild but It didn't work. Maybe I did it wrong?

1 answer

Try using WaitForChild

This is probably the problem. Use WaitForChild when you want to wait for children in an Instance. In our case, head and torso might not load when the character does.

function JustWelding (character)
    local head = character:WaitForChild("Head")
    local torso = character:WaitForChild("Torso")
    script.Parent.CFrame = head.CFrame * CFrame.new(0,0,-5)
    local weld = Instance.new("Weld")
    weld.Part0 = torso
    weld.C0 = torso.CFrame:inverse()
    weld.Part1 = script.Parent
    weld.C1 = script.Parent.CFrame:inverse()
    wait() 
    weld.Parent = script.Parent
    script.Parent.Anchored = false
end

game.Players.PlayerAdded:connect(function(player)
    player.CharacterAdded:connect(JustWelding)
end)

Checking output in an online game

When you're the creator of a place, you can press f9 while in game to see the Server log, Local log, and gain access to the command bar.

Good Luck!

If I helped, please don't forget to accept my answer.

5 comments

0

Didn't work. Plus server log didn't say anything wrong.

0

What's the wait on line 10 for? Try removing that.

0

I don't know why but the wait makes the script work. Without it, the script wouldn't work at all. Hmm weird.

0

Sorry I didn't get the right answer then ;-;.

0

Thanks for trying!

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