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

Where does the CFrame go after CharacterAdded?

Asked by 6 years ago
game.Players.PlayerAdded:Connect(function(Player)
    Player.CharacterAdded:Connect(function(Character)
        script.Parent.Jetpack1:Clone().Parent = Character
    end)
end)

I know that I need a CFrame after CharacterAdded, but I can't figure out where.

0
wait i got this CarMaster17 28 — 6y

2 answers

Log in to vote
0
Answered by 6 years ago
game.Players.PlayerAdded:Connect(function(Player)

    Player.CharacterAdded:Connect(function(Character)

        local clone = script.Parent.Jetpack1:Clone().
cone.Parent =  Character

    end)

end)
0
remove the . CarMaster17 28 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

You want to set the cframe before putting the object into workspace, it saves memory.

game.Players.PlayerAdded:Connect(function(Player)
    Player.CharacterAdded:Connect(function(Character)
         Torso = Character:WaitForChild("Torso”)
        JP = script.Parent.Jetpack1:Clone()
        JP.CFrame = Torso.CFrame
        JP.Parent = Character
    end)
end)

But there are still 2 problems with this script. 1. We are placing the jetpack at the same position as your torso, effectively putting it inside your character. 2. We are only setting the position once, so when you move the jetpack won't follow you. To fix this, we will offer offset the CFrame, and use a weld.

game.Players.PlayerAdded:Connect(function(Player)
    Player.CharacterAdded:Connect(function(Character)
         local weld = Instance.new(”Weld”)
         local Torso = Character:WaitForChild("Torso”)
         local JP = script.Parent.Jetpack1:Clone()
        JP.CFrame = Torso.CFrame
        weld.Parent = Torso
        weld.Part0 = Torso
        weld.Part1 = JP.Handle --you might need to change handle for another part in the jetpack
        weld.C0 = CFrame.new(0, 0, 1) -- this will place it .5 studs behind your back, which should make it look like it's sitting on your back
        JP.Parent = Character
    end)
end)
1
I've tried to do multiple scripts from different people, and I think they work, but the actual model for it is just spawning in the middle of the workspace. I have it in ServerScriptService, then I just put it in my character file when i'm testing the game. Undead_Ikimono 5 — 6y
0
Do you get any errors in the output? protectiveebob 221 — 6y

Answer this question