Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
1

Teleportation Script wont Tp Players, what is the problem?

Asked by 13 days ago

I created a game that teleports 4 players into a map and equipps them with sword. However, It says (Intermission) then (Game starts) AND THEN immedaitly after they were ectually supposed to teleport, nothing happens, but it says that Player 4 won and they receive the reward money: Heres the script, thank you in advance:

-- Define Variables

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local ServerStorage = game:GetService("ServerStorage")

local MapsFolder = ServerStorage:WaitForChild("Maps")

local Status = ReplicatedStorage:WaitForChild("Status")

local GameLength = 460

local reward = 30

-- Game Loop

while true do

    Status.Value = "Waiting for enough players"

    repeat wait() until game.Players.NumPlayers >= 4

    Status.Value = "Intermission"

    wait(10)

    local plrs = {}

    for i, player in pairs (game.Players:GetPlayers()) do
        if player then
            table.insert(plrs,player) -- add each player into plrs table
        end
    end

    wait(2)

    local AvailableMaps = MapsFolder:GetChildren()

    local ChosenMap = AvailableMaps[math.random(1,#AvailableMaps)]

    Status.Value = ChosenMap.Name.." Chosen"

    local ClonedMap = ChosenMap:Clone()
    ClonedMap.Parent= game.workspace

    -- Telporttion

        local SpawnPoints = ClonedMap:FindFirstChild("SpawnPoints")

        if not SpawnPoints then
            print("Spawnpoints not found!")
        end

        local AvailableSpawnPoints = SpawnPoints:GetChildren()

        for i, player in pairs(plrs) do
            if player then
                chracter = player.Character

                if character then
                    --teleport them

                    character:FindFirstChild("HumanoidRootPart").CFrame = AvailableSpawnPoints[1].CFrame
                    table.remove(AvailableSpawnPoints,1)


                    --give sword

                    local Sword = ServerStorage.Sword:Clone()
                    Sword.Parent = player.Backpack

                    local GameTag = Instance.new("BoolValue")
                    GameTag.Name = "GameTag"
                    GameTag.Parent = player.Character

                    else
                    --there is no character
                    if not player then
                        table.remove(plrs,i)
                    end
                end
            end
        end


        Status.Value = "You will be teleported soon. Get ready to play!"

        wait(20)

        for i = GameLength, 0, -1 do

            for x, player in pairs (plrs) do
                if player then

                    chracter = player.Character

                    if not chracter then
                        -- Left Game
                    else
                        if chracter:FindFirstChild("GameTag") then
                            -- they are still alive
                            print (player.Name.." is still in the game!")
                        else
                            --Theyre Dead
                            table.remove(plrs,x)
                            end
                        end
                    else
                        table.remove(plrs,x)
                        print(player.name.." has been removed!")

                end
                end

                Status.Value = "There are "..i.." seconds remaining, and "..#plrs.." players alive!"

                if #plrs == 1 then
                -- Last Person Standing
                Status.Value = "The winner is "..plrs[1].Name
                plrs[1].leaderstats.Coins.Value = plrs[1].leaderstats.Coins.Value + reward
                break
                elseif #plrs == 0 then
                    Status.Value = "Nobody won!!"
                    break
                elseif i == 0 then
                    Status.Value = "Time's up!"
                end


                        wait(1)
            end

            print("End of game")

            for i, player in pairs (game.Players:GetPlayers()) do
            chracter = player.Character

            if not chracter then
                -- ignore
            else
                if chracter:FindFirstChild("GameTag") then
                    chracter.GameTag:Destroy()
                end

                if player.Backpack:FindFirstChild ("Sword") then
                    player.Backpack.Sword:Destroy()
                end

                 if chracter:FindFirstChild ("Sword") then
                    chracter.Sword:Destroy()
                 end

            end

            player:LoadCharacter()
        end 

        ClonedMap:Destroy() 

        Status.Value = "Game Ended"

        wait(2)
end

1 answer

Log in to vote
0
Answered by
Miniller 336 Moderation Voter
13 days ago

Line 58 you are defining "chracter", but using "character" under

1
how am i so blind. Thank you so much Stuffy_flowerx3 3 — 12d
0
Please accept my answer. I'm glad I helped! :) Miniller 336 — 12d
Ad

Answer this question