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

PLAYERS DO NOT TELEPORT?

Asked by 4 years ago

Hi Thank You for your time i have a problem i want every player to move or teleport to different maps but it does not work and sometimes it does glitches here is the code i have different surfaces and every 30 seconds i want to teleport to the another map.

for y,players in pairs(plrs) do
            for i,surface in pairs(surfaces) do

                local gamecharacter=players.Character or players.CharacterAdded:Wait()
                if gamecharacter then

                    local surfacespowns=surface:FindFirstChild("Spown"):GetChildren()
                    wait(1)
                    gamecharacter:FindFirstChild("HumanoidRootPart").CFrame=surfacespowns[math.random(1,#surfacespowns)].CFrame                     
                    game:GetService("ReplicatedStorage").Desider.CanCollide=false
                    wait(30)
                else
                    if not players then

                        table.remove(plrs,i)
                    end
                end
                table.remove(surfaces,i)
            end



        end

thank you if u have a solution please answer my question.

2 answers

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

Please provide explanation with your answers. Simply posting code does not spread knowledge of integral scripting processes which helps people understand the logic and reasoning behind your answer.

You can use :MoveTo() to change a player/model position, please remember that your model will need to have a PrimaryPart

for y,players in pairs(plrs) do
            for i,surface in pairs(surfaces) do

                local gamecharacter=players.Character or players.CharacterAdded:Wait()
                if gamecharacter then

                    local surfacespowns=surface:FindFirstChild("Spown"):GetChildren()
                    wait(1)
                    gamecharacter:MoveTo(surfacespowns[math.random(1,#surfacespowns)].CFrame.position)                     
                    game:GetService("ReplicatedStorage").Desider.CanCollide=false
                    wait(30)
                else
                    if not players then

                        table.remove(plrs,i)
                    end
                end
                table.remove(surfaces,i)
            end



        end
0
hey thanks but on this line gamecharacter:MoveTo(surfacespowns[math.random(1,#surfacespowns)].Position) it gives me this error attempt to index number with 'Position' you_success -50 — 4y
1
Try it now, I edited the answer Leamir 3138 — 4y
0
ok you_success -50 — 4y
View all comments (11 more)
0
it gave me attempt to index number with 'CFrame' you_success -50 — 4y
0
can you explain me better what surfacespoints is? I need to know to fix the answer [If possible add it on the question] Leamir 3138 — 4y
0
servicespowns is a list of spwns in that map you_success -50 — 4y
0
spawns you mean the part? Leamir 3138 — 4y
0
no real spown points you_success -50 — 4y
0
so vector3 positions or CFrame? [If one of thease, please specify] Leamir 3138 — 4y
0
cframes you_success -50 — 4y
0
how do i know i guess vector3 you_success -50 — 4y
0
Add the variable at the question so I can see it, it will be easyer to fix Leamir 3138 — 4y
0
hi suurfacespown is a model in each surface local surfacespowns=surface:FindFirstChild("Spown"):GetChildren() and then i get a random spownpoint from that model and then try to teleport all players to random spownpoint in the map with is in the spownpoints model ans thank u for trying to solve my problem learmir you_success -50 — 4y
0
hi thank u this line solved everything character:FindFirstChild("HumanoidRootPart").CFrame=allspowns[math.random(1,#allspowns)].CFrame you_success -50 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

If your still having issues, try using CFrame.

local part1 = game.workspace.BluePart
local plr = game.Players:FindFirstChild("LocalPlayer")

plr.Character.HumanoidRootPart.CFrame = part1.CFrame * CFrame.new(0, 0, 1)

Read more on CFrames: https://developer.roblox.com/en-us/api-reference/datatype/CFrame

Answer this question