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)
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)
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
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.
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.
Is this script inside of the StarterCharacterScripts? It must be inside of there for your character reference to be correct
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!
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)