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

Vehicle falls apart if the player who was in it dies. Why?

Asked by 8 years ago

For some strange reason, in the turret I made, if a player gets in it, he/she is given a control tool for that turret, then if he/she gets out the turret control tool is removed. I don't know if that's part of the problem, but after he/she gets out, and dies somehow, the turret falls apart as if destroyed. I don't want that to happen, and I don't know how to fix it, help? Here's the scrip for it:

function onChildAdded(part)
if part.className == "Weld" then
    local torso = part.Part1
    if torso ~= nil then
        local parent = torso.Parent
        if parent ~= nil then
            local player = game.Players:findFirstChild(parent.Name)
            local turret = script.Parent.Parent.Parent.Parent
            turret.Parent = parent
            local tool = script.Turret:Clone()
            tool.Parent = player.Backpack
            script.Parent.Sound:play()
        end
    end
end
end


function onChildRemoved(part)
local player1 = game.Players:findFirstChild(script.Parent.Parent.Parent.Parent.Parent.Name)
player1.Backpack.Turret:remove()
script.Parent.Sound:stop()
end

script.Parent.ChildRemoved:connect(onChildRemoved)
script.Parent.ChildAdded:connect(onChildAdded)
1
Don't parent the turret to the player's character model. :BreakJoints() is called on the player model when they die. XAXA 1569 — 8y
0
So what should I do to make it not fall apart? Supergamerboy1995 129 — 8y

1 answer

Log in to vote
0
Answered by
Acheo 230 Moderation Voter
8 years ago
function onChildAdded(part)
if part.className == "Weld" then
    local torso = part.Part1
    if torso ~= nil then
        local parent = torso.Parent
        if parent ~= nil then
            local player = game.Players:findFirstChild(parent.Name)
            local turret = script.Parent.Parent.Parent.Parent
            turret.Parent = parent
            local tool = script.Turret:Clone()
            tool.Parent = game.Workspace
            script.Parent.Sound:play()
        end
    end
end
end


function onChildRemoved(part)
local player1 = game.Players:findFirstChild(script.Parent.Parent.Parent.Parent.Parent.Name)
player1.Backpack.Turret:remove()
script.Parent.Sound:stop()
end

script.Parent.ChildRemoved:connect(onChildRemoved)
script.Parent.ChildAdded:connect(onChildAdded)

Normally, things like this break apart due to them being inside of the player model.

0
So how do I make it not fall apart? Supergamerboy1995 129 — 8y
Ad

Answer this question