Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Saying Touched is a userdata Value? [CLOSED]

Asked by
Nckripted 580 Moderation Voter
4 years ago
Edited 4 years ago

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!

0
Please note that the way the parts are organized, I know it is a bit messy it's just how I do stuff. Nckripted 580 — 4y
0
I believe that "part" needs to be a refrence to a player/humanoid, not an object as you have it. Benbebop 1049 — 4y
0
Tried renaming it from part, didn't work. Nckripted 580 — 4y
0
And as far as I am concerned, the name doesn't matter of the parameter. Nckripted 580 — 4y
View all comments (2 more)
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. Benbebop 1049 — 4y
0
Nothing still, even with all your changes Nckripted 580 — 4y

1 answer

Log in to vote
0
Answered by
Nckripted 580 Moderation Voter
4 years ago

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

Ad

Answer this question