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

Saying Touched is a userdata Value? [CLOSED]

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

0

Please note that the way the parts are organized, I know it is a bit messy it's just how I do stuff.

0

I believe that "part" needs to be a refrence to a player/humanoid, not an object as you have it.

0

Tried renaming it from part, didn't work.

0

And as far as I am concerned, the name doesn't matter of the parameter.

0

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.

0

Nothing still, even with all your changes

1 answer

Just saying, I figured out the answer. I forgot connect :(. Thank you Benbebop for trying to help, I greatly appreciate that.

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