Boolean doesn't fire client to server event (UNSOLVED)

Hello, i want to send boolean client to server but it won’t work. Here codes:

LocalScript:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("TouchedEvent")

local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")

humanoid.Touched:Connect(function(hit)
	if hit.Name == "GamePart" then
		print("PlayerInGame")
	end
	remoteEvent:FireServer(true)
end)

Se.Sc.Service:

local function TeleportPlayers(boolean)
	
	local Spawns = SpawnsFolder:GetChildren()
	repeat task.wait(1) 
	for _, player in ipairs(Players:GetPlayers()) do
		local RandomSpawn = Spawns[math.random(1, #Spawns)]

		table.remove(Spawns, table.find(Spawns, RandomSpawn))
			player.Character:MoveTo(RandomSpawn.Position +  Vector3.new(0, 3, 0))
		
		end 
	until boolean == true
end

teleport.Event:Connect(TeleportPlayers)
touchevent.OnServerEvent:Connect(TeleportPlayers)
5 Likes

Are you getting any errors in the output window?

2 Likes

try this

local function TeleportPlayers(plr, boolean) -- plr represents the client that fired the event
	
	local Spawns = SpawnsFolder:GetChildren()
	repeat task.wait(1) 
	for _, player in ipairs(Players:GetPlayers()) do
		local RandomSpawn = Spawns[math.random(1, #Spawns)]

		table.remove(Spawns, table.find(Spawns, RandomSpawn))
			player.Character:MoveTo(RandomSpawn.Position +  Vector3.new(0, 3, 0))
		
		end 
	until boolean == true
end

teleport.Event:Connect(TeleportPlayers)
touchevent.OnServerEvent:Connect(TeleportPlayers)
3 Likes

Nope, i don’t get any error.

When i made it too nothing changed, when i try print Boolean it says my username in studio not true/false.

What do you mean until it equals true. You’re sending it when it is true which means the loop in theory would stop immediately. Think it’s a logic issue you need to fix

If player touched part then send true to server for stop loop.

1 Like

Has the function been started before the remote event?

Also are you sending the Boolean when the event is received cuz it doesn’t look like it.

Function in server already working. When player touched a part in localscript it fires event. Then sending to function in server. I just want to make stop the repeat until player touched part.

It still unsolved please someone help T-T

OnServerEvent’s First argument is the player who fired to the server, and then any additional arguments.

In your example TeleportPlayers(boolean) should be TeleportPlayers(player, boolean)

1 Like

Local:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("TouchedEvent")

local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")

humanoid.Touched:Connect(function(hit)
	if hit.Name == "GamePart" then
		print("PlayerInGame")
	end
	remoteEvent:FireServer(hit,true)
end)

Server:

local function TeleportPlayers(plr, boolean) -- plr represents the client that fired the event
	
	local Spawns = SpawnsFolder:GetChildren()
	repeat task.wait(1) 
	for _, player in ipairs(Players:GetPlayers()) do
		local RandomSpawn = Spawns[math.random(1, #Spawns)]

		table.remove(Spawns, table.find(Spawns, RandomSpawn))
			player.Character:MoveTo(RandomSpawn.Position +  Vector3.new(0, 3, 0))
		print(boolean)
		end 
	until boolean == true
end

teleport.Event:Connect(TeleportPlayers)
touchevent.OnServerEvent:Connect(TeleportPlayers)

Is it like that? could you please give more detail, it didnt work

Yes. Assuming that the connection above touchevent.OnServerEvent is a bindable event, then you would need to use a different function for that, because bindable events don’t pass players as a first argument.

1 Like

It wasnt bindable event, its just remoteevent, should i just change it? Sorry i am bad at thoose things

This is a bindable event right?

1 Like

Teleport is bindable event but Touchedevent is just remoteevent

Yes that’s what I’m saying. BindableEvents and RemoteEvents are not the same, so don’t use the same function to handle both Events.

Oh thats sad… I just wanted stop loop when player touched…

There are a few things you might wanna check:

  1. Is this script inside of the StarterCharacterScripts? It must be inside of there for your character reference to be correct
  2. You are running a repeat loop in your function; know that the boolean value in that specific function call will never be true when “false” has been sent from the client (because for the script to know it is true now, you will need to send another remote event)
    Let me know if this helped you out!

Yes, it is in startercharacter,

But i don’t understand part already connect player when it touched to part and fire event to send boolean, i cant understand why the loop don’t recieve boolean when it connected to remoteevent.

If you want to stop a loop with a remote event then use variables.

local stopTeleporting = false

task.spawn(function()
     while true and task.wait(1) do -- wait 1 second between each interval
         if not stopTeleporting then
             for _, player in ipairs(Players:GetPlayers()) do
		         local RandomSpawn = Spawns[math.random(1, #Spawns)]

		         table.remove(Spawns, table.find(Spawns, RandomSpawn))
			      player.Character:MoveTo(RandomSpawn.Position +  Vector3.new(0, 3, 0))
		         print(stopTeleporting)
		     end 
         end
     end
end)

local function handleOnServerEvent(player, boolean)
    stopTeleporting = boolean -- now the loop stops running
end

touchEvent.OnServerEvent:Connect(handleOnServerEvent)
1 Like