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

Teleporting players to another game?

Asked by 6 years ago

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.

1
localscripts do not have access to serverstorage nor serverscriptservice creeperhunter76 554 — 6y
1
ServerscriptStorage should also be used to house scripts, not values lukeb50 631 — 6y

1 answer

Log in to vote
0
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
6 years ago
Edited 6 years ago

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)
Ad

Answer this question