Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Teleporting players to another game?

Local script:

local TeleportService = game:GetService("TeleportService")
local plrs = game.ServerScriptService.Add.Players --numbervalue
local place = 1011676824
local plr = game.Players.LocalPlayer
text = script.Parent.Display

if plrs.Value >= 5 then
	text.Text = "The game is about to start!"
	text.TextColor3 = Color3.new(255,0,0)
	wait(3)
	TeleportService:Teleport(place,plr)
end

I have another script that adds to plrs.Value once a player joins the game. My script waits until there are 5 players then teleports them to another game. The problem is that this script works fine in studio but doesn't work in game. The error that only shows up in game is "ServerScriptService is not a valid member of DataModel." I don't understand this error since I defined ServerScriptService through the game.

2 comments

1

localscripts do not have access to serverstorage nor serverscriptservice

1

ServerscriptStorage should also be used to house scripts, not values

1 answer

✓ Accepted answer

You cannot access ServerScriptStorage, from the client.

Seems you're attempting to teleport the client once there are five players in the server. You need to establish a loop in order to consistently check the amount of players.

######note: you do not need to supply the plr parameter when using the Teleport function from the client

local TeleportService = game:GetService("TeleportService")
local place = 1011676824
local text = script.Parent:WaitForChild("Display") --May not have loaded

--Wait for minimum number of players
--This is an example of a 'repeat' loop
repeat wait() until #game.Players:GetPlayers() >= 5

text.Text = "The game is about to start!"
text.TextColor3 = Color3.new(255,0,0)
wait(3)
TeleportService:Teleport(place)

This discussion is preserved as it was. New answers, comments, and votes are closed.