local Players = game:GetService("Players")
local Workspace = game:GetService("Workspace")
local serverScriptService = game:GetService("ServerScriptService")
local folder = Workspace["Fight Request Pads Set 1"]
local fighting = Workspace["Fighting Map 1"].Value
fighting:GetPropertyChangedSignal("Value"):Connect(function()
if fighting.Value == true then
print("Fighting Value set to true")
local value1 = folder["Fight Request Pad 1"].Value.Value
local value2 = folder["Fight Request Pad 2"].Value.Value
local player1 = Players:FindFirstChild(value1)
local player2 = Players:FindFirstChild(value2)
if player1 and player2 and player1.Character and player2.Character then
local rootPart1 = player1.Character:FindFirstChild("HumanoidRootPart")
local rootPart2 = player2.Character:FindFirstChild("HumanoidRootPart")
if rootPart1 and rootPart2 then
local spawnFolder = Workspace["Fighting Map 1"]["Spawn Locations"]
local spawnParts = spawnFolder:GetChildren()
local randomSpawn1 = spawnParts[math.random(1, #spawnParts)]
local randomSpawn2 = spawnParts[math.random(1, #spawnParts)]
while randomSpawn1 == randomSpawn2 do
randomSpawn2 = spawnParts[math.random(1, #spawnParts)]
end
rootPart1.CFrame = randomSpawn1.CFrame
rootPart2.CFrame = randomSpawn2.CFrame
local humanoid1 = player1.Character:FindFirstChild("Humanoid")
local humanoid2 = player2.Character:FindFirstChild("Humanoid")
humanoid1.Died:Connect(function()
rootPart1.CFrame = Workspace.SpawnLocation.CFrame + Vector3.new(0, 3, 0)
rootPart2.CFrame = Workspace.SpawnLocation.CFrame + Vector3.new(0, 3, 0)
fighting.Value = false
end)
humanoid2.Died:Connect(function()
rootPart1.CFrame = Workspace.SpawnLocation.CFrame + Vector3.new(0, 3, 0)
rootPart2.CFrame = Workspace.SpawnLocation.CFrame + Vector3.new(0, 3, 0)
fighting.Value = false
end)
end
else
fighting.Value = false
print("One or both players are not valid")
end
end
end)
The players don’t get teleported back once someone else dies, and fighting stays true.
The function is not firing as there is no property change within ‘fighting,’ try showing the code that changes the value of ‘fighting’ to true such that the provided function is fired.
‘fighting’ is a bool value and it does fire, but near the end of the code when a player dies it is supposed to fire again to become false but it doesn’t, so the players never get teleported back.
Hi, I did some testing and feel like something like this would work;
local Players = game:GetService("Players")
local Workspace = game:GetService("Workspace")
local serverScriptService = game:GetService("ServerScriptService")
local folder = Workspace["Fight Request Pads Set 1"]
local fighting = Workspace["Fighting Map 1"].Value
local function TeleportBackAfterFighting(PlayerThatDied,OtherPlayersHRP)
local FunctionOne
FunctionOne = PlayerThatDied.CharacterAdded:Connect(function(Character)
PlayerThatDied.Character.HumanoidRootPart.CFrame = Workspace.SpawnLocation.CFrame + Vector3.new(0, 3, 0)
FunctionOne:Disconnect()
end)
OtherPlayersHRP.CFrame = Workspace.SpawnLocation.CFrame + Vector3.new(0, 3, 0)
end
fighting:GetPropertyChangedSignal("Value"):Connect(function()
if fighting.Value == true then
print("Fighting Value set to true")
local value1 = folder["Fight Request Pad 1"].Value.Value
local value2 = folder["Fight Request Pad 2"].Value.Value
local player1 = Players:FindFirstChild(value1)
local player2 = Players:FindFirstChild(value2)
if player1 and player2 and player1.Character and player2.Character then
local rootPart1 = player1.Character:FindFirstChild("HumanoidRootPart")
local rootPart2 = player2.Character:FindFirstChild("HumanoidRootPart")
if rootPart1 and rootPart2 then
local spawnFolder = Workspace["Fighting Map 1"]["Spawn Locations"]
local spawnParts = spawnFolder:GetChildren()
local randomSpawn1 = spawnParts[math.random(1, #spawnParts)]
local randomSpawn2 = spawnParts[math.random(1, #spawnParts)]
while randomSpawn1 == randomSpawn2 do
randomSpawn2 = spawnParts[math.random(1, #spawnParts)]
end
rootPart1.CFrame = randomSpawn1.CFrame
rootPart2.CFrame = randomSpawn2.CFrame
local humanoid1 = player1.Character:FindFirstChild("Humanoid")
local humanoid2 = player2.Character:FindFirstChild("Humanoid")
humanoid1.Died:Connect(function()
TeleportBackAfterFighting(player1,rootPart2)
fighting.Value = false
end)
humanoid2.Died:Connect(function()
TeleportBackAfterFighting(player2,rootPart1)
fighting.Value = false
end)
end
else
fighting.Value = false
print("One or both players are not valid")
end
end
end)
still need help May someone please check the rbxl file and try to find the issue? It’s a duel system and if a player dies then both players are supposed to get teleported back but the player that doesn’t die just gets teleported to another random spawn of the map.