Hey there! I am trying to make a system where you press a button and it searches for players who did as well. Everything I tried so far resulted in failure so I decided to come here for some advice.
Here is the script I am using right now. The problem is that the player only gets teleported to SpawnP1
and so does the other player. None of them go to SpawnP2
.
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local spinEvent = game.ReplicatedStorage:WaitForChild("Events"):WaitForChild("SpinBananaEvent")
local readyEvent = game.ReplicatedStorage:WaitForChild("Events"):WaitForChild("ReadyEvent")
local enableFightEvent = game.ReplicatedStorage:WaitForChild("Events"):WaitForChild("EnableFightEvent")
local teleportEvent = game.ReplicatedStorage:WaitForChild("Events"):WaitForChild("TeleportEvent")
local searching = false
enableFightEvent.OnClientEvent:Connect(function(player)
if player.Name == player then
searching = false
script.Parent.Enabled = false
teleportEvent:FireServer(workspace.Map1.SpawnP2.CFrame)
end
end)
spinEvent.Event:Connect(function(bool)
print("Searching Started")
if bool then
searching = true
while searching do
wait(1)
for i, v in pairs(game.Players:GetPlayers()) do
if searching then
local ready = v:FindFirstChild("Ready")
local isPlayingOpp = v:FindFirstChild("IsPlaying")
if ready.Value and not isPlayingOpp.Value and v.Name ~= player.Name and searching then
searching = false
readyEvent:FireServer("IsPlaying", true)
readyEvent:FireServer("Ready", false)
script.Parent.Enabled = false
enableFightEvent:FireServer(v.Name)
teleportEvent:FireServer(workspace.Map1.SpawnP2.CFrame)
end
end
end
end
elseif not bool then
searching = false
end
end)
Any help is greatly appreciated!