Minigame Teleport System Not Working

:wave: 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”.

image
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

image
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):
image

:hugs: Any help or insight you can provide will be helpful. Thanks!

1 Like

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

1 Like

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.

Does Teleports or Part(Number) exists?

1 Like

Teleports is the model which contains the Parts.
image

Part…num are the parts inside of Teleports. The num is generated through math.random(1,16) so that the teleport is random.

Hello. Luckily for you, I’m using the same script for my mini game game I’m working on right now!

So, let me clear some things up first: is Stat a StringValue? If not, it won’t work.

1 Like

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.

Huh, now it’s not working for me either. I think one of Roblox’s updates messed it up

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.

2 Likes

Yep! Stat is a stringValue.

30characters

Awesome! Thank you for your help.

Hey, instead of using repeat I suggest using a for loop!

sorry for bad indent I’m on phone

for i=100,0,-1 do
 s.Value = i .. " seconds left"
end

and in the localscript instead of doing a while loop just check when Stat.Value changed :slightly_smiling_face:

Stat: GetPropertyChangedSignal ("Value"):Connect(function()
 -- ur code
end)