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

[FIXED] 13: bad argument #2 (string expected, got nil)?

Asked by 4 years ago
Edited 4 years ago

I have a remote that will teleport a player to another player. Here is the script

script.Parent.OnServerEvent:Connect(function(_, tp1, tp2)
    function shortenName(name)
        local ReturnedName
        for i,v in pairs(game.Players:GetPlayers()) do
            if v.Name:sub(1,name:len()):lower()== name:lower() then
                ReturnedName = v.Name
            end
        end 
        return ReturnedName
    end
    tp1 = shortenName(tp1)
    tp2 = shortenName(tp2)
    workspace[tp1].HumanoidRootPart.Position = workspace[tp2].HumanoidRootPart.Position
end)

Here is my localscript

script.Parent.MouseButton1Click:Connect(function()
    script.Parent.Parent.Parent.Remotes.tp:FireServer(script.Parent.Parent.Parent.player.Text, game.Players.LocalPlayer.Name)
end)

The error: Players.7izr.PlayerGui.PlayerGui.gui.Remotes.tp.Script:13: bad argument #2 (string expected, got nil)

I have since fixed it. Its getting the list of children in game.Players but im trying to teleport a dummy that is not in game.Players

0
I printed tp1 and tp2 and it print nil,7izr zymletal 37 — 4y
0
You don't have to send the player parameter to the server script. It automatically picks up who the player is. Tp2 is not needed. I don't know what you're trying to do with the underscore as your first argument though. AntiWorldliness 868 — 4y
0
the script isn't taking into account the possibility that one of the players may not exist elitekiller2342 87 — 4y

Answer this question