So, I was making a script to teleport players into a car, and I could not figure out for the life of me why I was getting this error:
14:39:18.497 - Workspace.Part.Script:53: attempt to call a userdata value
14:39:18.498 - Stack Begin
14:39:18.499 - Script 'Workspace.Part.Script', Line 53
14:39:18.499 - Stack End
This is my script I was using:
local this = script.Parent
local transporting = false
--Get all the seats available for sitting
function getAllSeats()
frontSeats = {}
backSeats = {}
--Get all front seats in cars
for key,value in pairs (workspace.TransportJeep1.FrontJeep:GetChildren()) do
if value:IsA("Seat") then
table.insert(frontSeats,#frontSeats + 1,value)
end
end
for key,value in pairs (workspace.TransportJeep.FrontJeep:GetChildren()) do
if value:IsA("Seat") then
table.insert(frontSeats,#frontSeats + 1,value)
end
end
--Get all back seats in car
for key,value in pairs (workspace.TransportJeep1.BackWall:GetChildren()) do
if value:IsA("Seat") then
table.insert(backSeats,#backSeats + 1,value)
end
end
for key,value in pairs (workspace.TransportJeep.BackWall:GetChildren()) do
if value:IsA("Seat") then
table.insert(backSeats,#backSeats + 1,value)
end
end
end
function assignToSeat(part)
local rootpart = part.Parent:FindFirstChild("HumanoidRootPart")
local seatToAssign
if #frontSeats > 0 then
seatToAssign = frontSeats[math.random(1,#frontSeats)]
rootpart.CFrame = CFrame.new(seatToAssign.Position)
return true
end
if #backSeats > 0 then
seatToAssign = backSeats[math.random(1,#backSeats)]
rootpart.CFrame = CFrame.new(seatToAssign.Position)
return true
end
return false
end
this.Touched(function(part)
assignToSeat(part)
end)
Any help would be greatly appreciated!

6 comments
Please note that the way the parts are organized, I know it is a bit messy it's just how I do stuff.
I believe that "part" needs to be a refrence to a player/humanoid, not an object as you have it.
Tried renaming it from part, didn't work.
And as far as I am concerned, the name doesn't matter of the parameter.
That isnt what I meant though I think its a slightly different problem, remove the "function" on line 53 and just have "this.Touched(part)". See if that works.
Nothing still, even with all your changes