local entrance = script.Parent
local teleService = game:GetService("TeleportService")
local lvlPicker = game.ReplicatedStorage.mapchooser
local teleHandler = game.ReplicatedStorage.TeleportHandler
local safeTele = require(game.ServerScriptService.SafeTeleport)
local plrsWaiting= {}
local maps = {
Namek = 100551075524265,
Lobby = 109808845530016
}
entrance.Touched:Connect(function(toucher)
if toucher.Parent:FindFirstChild("Humanoid") and #plrsWaiting == 0 then
local plr = game.Players:GetPlayerFromCharacter(toucher.Parent)
local mapChooser = lvlPicker:Clone()
table.insert(plrsWaiting, plr)
plr.Character.HumanoidRootPart.Position = game.Workspace.step.Position + Vector3.new(0,2,0)
mapChooser.Parent = plr.PlayerGui
teleHandler:FireClient(plr, plr)
elseif #plrsWaiting < 0 then
local plr = game.Players:GetPlayerFromCharacter(toucher.Parent)
table.insert(plrsWaiting, plr)
plr.Character.HumanoidRootPart.Position = game.Workspace.step.Position + Vector3.new(0,2,0)
end
end)
teleHandler.OnServerEvent:Connect(function(plr, difficulty, location)
local mapChooser = plr.PlayerGui.mapchooser
if difficulty.Name == "exit" then
plr.Character.HumanoidRootPart.Position = game.Workspace.SpawnLocation.Position + Vector3.new(0,2,0)
end
if location.Name == "namek" then
print("namek")
elseif location.Name == "main" then
print("lobby")
end
for i,v in pairs(plrsWaiting) do
table.remove(plrsWaiting, i)
end
end)
I quite literally have no clue what is going on. it works the first time but after that it just does not fire. i put a print in the client call and literally 0. not too sure how that is possible especially when the remote event does not get deleted at all. The local script exists inside the gui and gets replicated alongside it so its not like the script is just randomly disappearing. I’ve tried running the destroy on both server and client and still it persists
I wouldn’t send objects/instances references through a RemoteEvent. I recomend you send information regarding your difficulty selection as a string or number.
I also changed a bit of the script, I see you do if #plrsWaiting < 0 which will never be negative.
local entrance = script.Parent
local teleService = game:GetService("TeleportService")
local lvlPicker = game.ReplicatedStorage.mapchooser
local teleHandler = game.ReplicatedStorage.TeleportHandler
local safeTele = require(game.ServerScriptService.SafeTeleport)
local plrsWaiting= {}
local maps = {
Namek = 100551075524265,
Lobby = 109808845530016
}
entrance.Touched:Connect(function(toucher)
if toucher.Parent:FindFirstChild("Humanoid") and #plrsWaiting == 0 then
local plr = game.Players:GetPlayerFromCharacter(toucher.Parent)
local mapChooser = lvlPicker:Clone()
table.insert(plrsWaiting, plr)
plr.Character.HumanoidRootPart.Position = game.Workspace.step.Position + Vector3.new(0,2,0)
mapChooser.Parent = plr.PlayerGui
teleHandler:FireClient(plr, plr)
elseif #plrsWaiting > 0 then
local plr = game.Players:GetPlayerFromCharacter(toucher.Parent)
table.insert(plrsWaiting, plr)
plr.Character.HumanoidRootPart.Position = game.Workspace.step.Position + Vector3.new(0,2,0)
end
end)
teleHandler.OnServerEvent:Connect(function(plr, difficulty, location)
local mapChooser = plr.PlayerGui.mapchooser
if difficulty.Name == "exit" then
plr.Character.HumanoidRootPart.Position = game.Workspace.SpawnLocation.Position + Vector3.new(0,2,0)
end
if location.Name == "namek" then
print("namek")
elseif location.Name == "main" then
print("lobby")
end
for i,v in pairs(plrsWaiting) do
table.remove(plrsWaiting, i)
end
end)
for this with fireclient you need to pass the player as the first variable for some reason but if you try to reference it it gets passed as nil so if i want to reference the player in the local script i had to pass it twice. i might be missing a way to do it properly tho
for fireclient i tried running just a single plr but it would not run i would constantly get the error trying to reference nil. i would print plr in the main server script and it would be me but if i tried to print plr in the client it would print nil so for some reason the first has to be there but it does not get referenced but also represents the player. it really threw me off
trying to make a teleporter to a different place using a gui but in the way tower defense games do which is stepping on a platform first. the server script is first and it fires to the local which then fires back to the server. also trying to make it so if there is alr a person in there creating a map no one else gets the gui which is hwy i have that check
I recomend a different aproach for detecting players in the teleporter. My script I sent detects the humanoids that are found inside a part. Use a system like this to detect who’s inside.
local heal : Part = script.Parent.HealRange
function getHumanoids()
local humans : {Humanoid} = {}
local parts = workspace:GetPartsInPart(heal)
for i, part in pairs(parts) do
if part.Parent:FindFirstChildWhichIsA("Humanoid") and not table.find(humans, part.Parent:FindFirstChildWhichIsA("Humanoid")) then
table.insert(humans,part.Parent:FindFirstChildWhichIsA("Humanoid"))
end
end
return humans
end
while true do
task.wait(1)
local humans = getHumanoids()
for i, human in pairs(humans) do
human.Health += 1
end
end