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

Unable to cast value to Object with TeleportPartyAsync?

Asked by
kepiblop 124
4 years ago
Edited 4 years ago

Hello i am making a thing where if you touch a part you are going to be queued for a game however the teleport party async function is saying 10:24:31.416 - Stack End 10:24:31.452 - Unable to cast value to Object 10:24:31.456 - Stack Begin 10:24:31.457 - Script 'Workspace.Part.Script', Line 34 10:24:31.459 - Stack End This may be because of the hierarchy https://cdn.discordapp.com/attachments/729539918094794827/750395116325437591/unknown.png

here is the code

local players = {}
local debounce = false
if debounce == false then
    debounce = true
script.Parent.Touched:Connect(function(hit)
        local player = game.Players:GetPlayerFromCharacter(hit.Parent)
        table.insert(players, 1, hit.Parent.Name)
    local humanoid = hit.Parent:FindFirstChild("Humanoid")
        if humanoid then
            humanoid.WalkSpeed = 0
            humanoid.JumpPower = 0
            humanoid.Parent.HumanoidRootPart.Position = game.Workspace.ParkBench.Seat1.Position
            game.Workspace.ParkBench.Seat1.Value.Value = true
            if game.Workspace.ParkBench.Seat1.Value.Value == true then
                humanoid.Parent.HumanoidRootPart.Position = game.Workspace.ParkBench.seat2.Position
                game.Workspace.ParkBench.seat2.Value.Value = true
            end
            if game.Workspace.ParkBench.seat2.Value.Value == true then

                humanoid.Parent.HumanoidRootPart.Position = game.Workspace.ParkBench.Seat3.Position
                game.Workspace.ParkBench.Seat3.Value.Value = true
            end
            if game.workspace.ParkBench.Seat3.Value.Value == true then
                script.Parent.Parent.BusStopShelter.Players.Value = 3
            end
            humanoid.WalkSpeed = 0
            humanoid.JumpPower = 0
            debounce = false

            if script.Parent.Parent.BusStopShelter.Players.Value == 3 then
                local animator = require(game.Workspace.Leave.Animator)
                animator.NewTween:Play()
                local teleportservice = game:GetService("TeleportService") --right here
                teleportservice:TeleportPartyAsync(removedid, players) --something is wrong with this part
            end
    end
    end)    
    wait(5)
    table.remove(players, 1)
    table.remove(players, 2)
    table.remove(players, 3)
end

Any help is appreciated

1 answer

Log in to vote
0
Answered by
Leamir 3138 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

You need to pass the player object instead of the player name inside of the table to that function

Also, when removing objects from a table using table.remove, the table is shifted

local players = {}
local debounce = false
if debounce == false then
    debounce = true
script.Parent.Touched:Connect(function(hit)
        local player = game.Players:GetPlayerFromCharacter(hit.Parent)
        table.insert(players, 1, hit.Parent) -- instead of adding player name to the table, add the object
    local humanoid = hit.Parent:FindFirstChild("Humanoid")
        if humanoid then
            humanoid.WalkSpeed = 0
            humanoid.JumpPower = 0
            humanoid.Parent.HumanoidRootPart.Position = game.Workspace.ParkBench.Seat1.Position
            game.Workspace.ParkBench.Seat1.Value.Value = true
            if game.Workspace.ParkBench.Seat1.Value.Value == true then
                humanoid.Parent.HumanoidRootPart.Position = game.Workspace.ParkBench.seat2.Position
                game.Workspace.ParkBench.seat2.Value.Value = true
            end
            if game.Workspace.ParkBench.seat2.Value.Value == true then

                humanoid.Parent.HumanoidRootPart.Position = game.Workspace.ParkBench.Seat3.Position
                game.Workspace.ParkBench.Seat3.Value.Value = true
            end
            if game.workspace.ParkBench.Seat3.Value.Value == true then
                script.Parent.Parent.BusStopShelter.Players.Value = 3
            end
            humanoid.WalkSpeed = 0
            humanoid.JumpPower = 0
            debounce = false

            if script.Parent.Parent.BusStopShelter.Players.Value == 3 then
                local animator = require(game.Workspace.Leave.Animator)
                animator.NewTween:Play()
                local teleportservice = game:GetService("TeleportService") --right here
                teleportservice:TeleportPartyAsync(removedid, players) --something is wrong with this part
            end
    end
    end)    
    wait(5)
    table.remove(players, 1)
    table.remove(players, 1) -- here should  be 1 instead of 2 because we are shifting the table
    table.remove(players, 1) -- here should  be 1 instead of 3 because we are shifting the table
end
0
Thanks alot i haven't tested this yet but i ensure this will work cause this looks trustworthy! kepiblop 124 — 4y
0
You should test it before accepting, everyone does mistakes, specially without testing Leamir 3138 — 4y
0
Oh okay kepiblop 124 — 4y
Ad

Answer this question