Client wont respond to server call more than once

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

1 Like

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)

I would remake the entire script.

1 Like

Also, fix: teleHandler:FireClient(plr, plr) to teleHandler:FireClient(plrsWaiting, plr)

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

1 Like

the data transfer thing works fine for me its just for some reason if i touch the door again the gui pops up but the event doesnt fire at all

oops, the opposite to all of them (plr first, then plrsWaiting)

make it playersWaiting > 0

djdskhfgrtoufyj

1 Like

yeah i changed that and another error popped up so im p sure thats why its not working in the main thing. ill figure it out for a bit

there’s something else going on because plr twice ain’t correct unless it’s a different value for the player

What are you even trying to do?

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
1 Like

Try not passing the player twice. plrsWaiting being player could be the issue. Change to string when you pass it to the client via fireclient

1 Like

Your current script has no way to tell if it has duplicate players either.

Also to simplify difficulty, just make a teleporter for each difficulity.

2 Likes

ok ill check it out the way i currently check is if they touch a wall they get teleported to a certain location

My way detects all player Characters inside of a part that represents the teleporter area.

touched events are unreliable, and how do you detect if they left it for instance.

the client im sending it to is just to select the difficulty and level

Yeah so make a separate teleporter for each difficulty. If you select difficulty with gui, don’t even bother with a teleporter.

1 Like

ah i see. i was just planning to make it so that they just either can walk out or it becomes cancollide and they cant leave unless they press exit