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

01local players = {}
02local debounce = false
03if debounce == false then
04    debounce = true
05script.Parent.Touched:Connect(function(hit)
06        local player = game.Players:GetPlayerFromCharacter(hit.Parent)
07        table.insert(players, 1, hit.Parent.Name)
08    local humanoid = hit.Parent:FindFirstChild("Humanoid")
09        if humanoid then
10            humanoid.WalkSpeed = 0
11            humanoid.JumpPower = 0
12            humanoid.Parent.HumanoidRootPart.Position = game.Workspace.ParkBench.Seat1.Position
13            game.Workspace.ParkBench.Seat1.Value.Value = true
14            if game.Workspace.ParkBench.Seat1.Value.Value == true then
15                humanoid.Parent.HumanoidRootPart.Position = game.Workspace.ParkBench.seat2.Position
View all 42 lines...

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

01local players = {}
02local debounce = false
03if debounce == false then
04    debounce = true
05script.Parent.Touched:Connect(function(hit)
06        local player = game.Players:GetPlayerFromCharacter(hit.Parent)
07        table.insert(players, 1, hit.Parent) -- instead of adding player name to the table, add the object
08    local humanoid = hit.Parent:FindFirstChild("Humanoid")
09        if humanoid then
10            humanoid.WalkSpeed = 0
11            humanoid.JumpPower = 0
12            humanoid.Parent.HumanoidRootPart.Position = game.Workspace.ParkBench.Seat1.Position
13            game.Workspace.ParkBench.Seat1.Value.Value = true
14            if game.Workspace.ParkBench.Seat1.Value.Value == true then
15                humanoid.Parent.HumanoidRootPart.Position = game.Workspace.ParkBench.seat2.Position
View all 42 lines...
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