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

Player not going back to the map with a weapon?

Asked by 4 years ago

Hi everyone!

I was making code for whenever someone died, that a script would run that checks if the player was in the round already, and if they were, to teleport them back to map with a weapon. It wouldn't work so I put prints in the code to see where it had stopped:

(This is a regular script)

Main = require(game.Workspace.ModuleScripts.Main)
local playersinround = Main.CharacterList
local players = game:GetService("Players"):GetPlayers()
local SwordAccess = game:GetService("ReplicatedStorage").Swords

local sword = SwordAccess.BasicSword

game:GetService("Players").PlayerAdded:Connect(function(plr)
    plr.CharacterAdded:Connect(function(charModel)
        charModel:WaitForChild("Humanoid").Died:Connect(function()
            playersinround = Main.CharacterList
            print(plr)
            plr.CharacterAdded:Wait(0.05)
            for i = 1, #playersinround do
                local player = playersinround[i]
                print(player)
                if player == plr then
                    print("1")
                    Main.ToBattleMap()
                    print("2")
                    local backpack = player:WaitForChild("Backpack")
                    if backpack then
                        local swordClone = sword:Clone()
                        swordClone.Parent = player
                        print("3")
                    end
                end
            end
        end)
    end)
end)

For some odd reason, all 4 prints print out in the output, but nothing happens in-game (No teleportation or weapon given). Can anyone tell me on how to fix this?

Any help on how to fix my code so it works is appreciated :)

0
Try making the wait set to something like 3-5 seconds. Raccoonyz 1092 — 4y

Answer this question