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

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

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.

9 comments

0

Where is your ending for the PlayerAdded?

1

Oops. Forgot to add that. It's in the script, I just didn't post it.

0

Alright I edited the post to include the PlayerAdded

0

ChildAdded**, in line 07 the player part doesn't make sense.

0

It worked before, nowI have no idea why it is not working now.

0

I believe you have to use the "GetPlayerFromCharacter"

0

Then it must be the ROBLOX Update.

0

No ROBLOX update took place has occurred in the past day, at least as far as I know

0

I think I fixed it. Thanks

1 answer

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.

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