Hello!
I am working on a simple minigame round system, where a countdown starts and once it ends, it teleports players to a random “teleportation brick”.
Inside my Main script, I have the following code:
local s = script.Stat
t = 0
while true do
t = 15
repeat
t = t-1
s.Value = "Intermission.. "..t
wait(1)
until t == 0
s.Value = "Round Starting"
wait(2)
local plrs = game.Players:GetChildren()
for i = 1, #plrs do
local num = math.random(1,16)
plrs[i].Character.Head.CFrame = CFrame.new(workspace.Teleports["Part"..num].Position)
end
t = 100
repeat
t = t-1
s.Value = t.." seconds left"
wait(1)
until t == 0
end
Inside my countdown GUI, I have the following script:
while wait () do
script.Parent.Text = workspace.Main.Stat.Value
end
These are the bricks in workspace which are being chosen to teleport to at random (math.random):
Any help or insight you can provide will be helpful.Thanks!
So are you sure it even reaches the part where it teleports the players?
If so I’d highly recommend not teleporting a player via their head. Try setting the CFrame of their HumanoidRootPart
I’ve tried changing it to HumanoidRootPart, however, I believe the error must be coming before this, as it doesn’t teleport at all. The countdown works, but once it reaches “Round Starting,” nothing happens.
you could try using the :MoveTo() event, on the character model, but i would have to go in a game to check out the script, does it give you any errors?
In this case the client overrides the server on location of the character. Have the script send a remote event to the client where the client handles the teleport. If you can’t figure out how to get this done approach me privately and I’ll send you a method provided with code.
local s = script.Stat
t = 0
while true do
t = 15
repeat
t = t-1
s.Value = "Intermission.. "..t
wait(1)
until t == 0
s.Value = "Round Starting"
wait(2)
local plrs = game.Players:GetChildren()
for i = 1, #plrs do
local num = math.random(1,16)
plrs[i].Character:MoveTo(workspace.Teleports["Part"..num].Position) -- EDITED LINE
end
t = 100
repeat
t = t-1
s.Value = t.." seconds left"
wait(1)
until t == 0
end
Instead of setting their head CFrame, I simply call the :MoveTo() function on the player’s Character model, which moves it to said position. You can call :MoveTo() on any model, by the way.