Can't make player sit in vehicleseat after pressing GUI

Alright,

I’ve made a boat spawner that works well. But, i’m trying to make it so that after you’ve clicked the Button on the GUI to spawn it, the character is teleported to the new cloned vehicle’s VehicleSeat.

Here’s what i’ve tried so far. The GUI comes up after pressing a spawn block thing, so it uses a regular script first to give you the GUI. The script below is the regular script inside of the button for the ship you want to spawn.

local player = game.Players.LocalPlayer
local humrootpart = player.Character.HumanoidRootPart

script.Parent.MouseButton1Click:Connect(function()
	local ship = game.ServerStorage.Ships.Ferecua.IslandClass
	local clone = ship:Clone()
	local seat = clone.VehicleSeat
	
	clone.Parent = workspace
	
	humrootpart.CFrame.new =  seat.CFrame
	
	script.Parent.Parent.Parent.Visible = false
	script.Parent.Parent.Parent.Parent.Parent.ClickDetector.MaxActivationDistance = 0
	wait(30)
	script.Parent.Parent.Parent.Parent.Parent.ClickDetector.MaxActivationDistance = 32
end)

Workspace.GameFolders.Spawners.Ferecua.DisburnSpawner.ScreenGui.Outer.Inner.IslandClass.Script:2: attempt to index nil with 'Character' - Server - Script:2

When I test it, I am presented with "attempted to index nil with ‘Character’, even though its a valid property inside of the player? i’m not sure if it’s because it’s a regular script or…

Any help would be appreciated, this is my first time trying to make this sort of thing.

1 Like

Try using a WaitForChild to get it if the player isn’t loaded yet.
local humrootpart = player:WaitForChild("HumanoidRootPart")

You may also need to use MoveTo to teleport the player.

Can you show an example of how to use MoveTo?

That’s why I posted the blue links.

ah right didn’t see that, thanks

local player = game.Players.LocalPlayer
local humrootpart = player.Character.WaitForChild("HumanoidRootPart")

script.Parent.MouseButton1Click:Connect(function()
	local ship = game.ServerStorage.Ships.Ferecua.IslandClass
	local clone = ship:Clone()
	local seat = clone.VehicleSeat
	local endpos = seat.CFrame
	
	clone.Parent = workspace
	
	humrootpart.CFrame = seat.CFrame
	
	script.Parent.Parent.Parent.Visible = false
	script.Parent.Parent.Parent.Parent.Parent.ClickDetector.MaxActivationDistance = 0
	wait(30)
	script.Parent.Parent.Parent.Parent.Parent.ClickDetector.MaxActivationDistance = 32
end)

still isn’t working, I think it may be because it’s in a normal script and it’s trying to get the localplayer, but i’m not sure how to convert it to a localscript

1 Like

Just put a Local script in the same location and cut/paste this script into it then delete the server script.