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

Why is this script that makes vehicle become a child of a player's character not working?

Asked by 9 years ago

When you sit in a seat, the script is supposed to make the vehicle become a child of the player's character. However, the script is not working, and I have no idea why it is doing this. Output did give me something. Can someone please help me? Here's the script:

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)
                script.Parent.Parent.Parent.Parent.Parent = parent
                local tool = script.Turret:Clone()
                tool.Parent = player.Backpack
            end
        end
    end
end


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

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

Output: 19:25:13.768 - Attempt to set Workspace.Player as its own parent 19:25:13.768 - Script 'Workspace.Tank.Turret.Device.Seat.Seracore', Line 8

This is the organization of the model: Tank>Turret>Device>Seat>The script (Seracore)

Then the model goes into the player's character and becomes a child of the player's character.

0
Where is your ending for the PlayerAdded? woodengop 1134 — 9y
1
Oops. Forgot to add that. It's in the script, I just didn't post it. CoolJohnnyboy 121 — 9y
0
Alright I edited the post to include the PlayerAdded CoolJohnnyboy 121 — 9y
0
ChildAdded**, in line 07 the player part doesn't make sense. woodengop 1134 — 9y
View all comments (5 more)
0
It worked before, nowI have no idea why it is not working now. CoolJohnnyboy 121 — 9y
0
I believe you have to use the "GetPlayerFromCharacter" woodengop 1134 — 9y
0
Then it must be the ROBLOX Update. woodengop 1134 — 9y
0
No ROBLOX update took place has occurred in the past day, at least as far as I know CoolJohnnyboy 121 — 9y
0
I think I fixed it. Thanks CoolJohnnyboy 121 — 9y

1 answer

Log in to vote
0
Answered by 9 years ago

The error means you are accidentally executing the command "workspace.Player.Parent = workspace.Player". I'm guessing you had one too many ".Parent" 's on line 8 (based on your comments, I'm not sure if you're saying the current script is functional or not).

It might be easier to work with if you assign "script.Parent.Parent.Parent.Parent" to a variable, making it easier to fix if you have too many or too few ".Parent"s.

Ad

Answer this question