You can write your topic however you want, but you need to answer these questions:
I need players who touch a part to be teleported to a private server but this code does nothing…
Any suggestions?
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
local Event = game.ReplicatedStorage:WaitForChild("RemoteEvent")
local Player = game.Players.LocalPlayer
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local PlrTable = {}
table.insert(PlrTable, hit.Parent.Name)
Event:FireServer(PlrTable)
end
end)
Ok, you should definitely be doing this on the server because an exploiter could easily fire that remote event and give a table that includes all the players. And local scripts don’t run on workspace.
You also can’t use teleport service in studio, you will have to play test it in actual Roblox.
-- server script in ServerScriptService
local TS = game:GetService("TeleportService")
local Part = workspace.Part
Part.Touched:Connect(function(otherPart)
if otherPart.Parent:FindFirstChildWhichIsA("Humanoid") then
local success,err = pcall(function() -- to get the error incase it does error
local code = TS:ReserveServer(game.PlaceId)
local plr = game.Players:GetPlayerFromCharacter(otherPart.Parent)
TS:TeleportToPrivateServer(game.PlaceId,code,{ plr })
end)
if not success then -- it errored, print the error
warn("Could not teleport " .. otherPart.Parent.Name .. "! Error : " .. err)
end
end
end)
Make sure you are using the same server everytime, don’t make a new server for each player. I’ve made this mistake before and it was quite hard to fix.