I've tried to define a variable "occupant" to act as the player, code I used (with all essential parts included) solutions would be appreciated!
local seat = script.Parent
local data = seat.Configuration
local owner = nil
local running = false
local Users = game.Players
local x=0
local y=0
seat.ChildAdded:connect(
function(w)
if w.className=="Weld" and w.Name=="SeatWeld" then
local char=w.Part1.Parent
print(char)
local occupant = game.Players["char"] --Here is the problem code line.
print(occupant)
local mouse = occupant:GetMouse()
print(mouse)
local player=game.Players:FindFirstChild(char.Name)
if player~=nil then
owner=player
seat.ChildRemoved:connect(function(w2)
if w2==w then
owner=nil
end
end)
local spd = 0
local gui = seat.ScreenGui:clone()
seat.BodyVelocity.maxForce=Vector3.new(1,1,1)*data.MaxForce.Value
seat.BodyGyro.maxTorque=Vector3.new(1,1,1)*50000
gui.Parent = player.PlayerGui
while owner==player do
seat.BodyVelocity.velocity=seat.CFrame.lookVector*spd
wait()
end
gui:remove()
seat.BodyVelocity.velocity=Vector3.new(0,0,0)
seat.BodyVelocity.maxForce=Vector3.new(0,0,0)
seat.BodyGyro.maxTorque=Vector3.new(0,0,0)
end
end
end)
mouse.KeyDown:connect(function()
print("test")
end)
bailey_chap
12:58:34.602 - char is not a valid member of Players
12:58:34.602 - Stack Begin
12:58:34.603 - Script 'Workspace.PlaneSeat.Script', Line 18
12:58:34.603 - Stack End

1 comment
use char:GetPlayerFromCharacter() (https://developer.roblox.com/en-us/api-reference/function/Players/GetPlayerFromCharacter)