Nothing is happening and there are no errors shown in my output

The 2 players usernames are stored as string values from other scripts.
I don’t know what the issue is, since no errors or warnings are shown in the output.

local Players = game:GetService("Players")
local Workspace = game:GetService("Workspace")
local serverScriptService = game:GetService("ServerScriptService")
local folder = Workspace["Fight Request Pads Set 1"]
local value1 = folder["Fight Request Pad 1"].Value.Value
local value2 = folder["Fight Request Pad 2"].Value.Value
local fighting = Workspace["Fighting Map 1"].Value

fighting:GetPropertyChangedSignal("Value"):Connect(function()
	if fighting.Value == true then
		local player1 = Players:FindFirstChild(value1)
		local player2 = Players:FindFirstChild(value2)
		local scriptsFolder = serverScriptService["Fight Requests Managers"]["Set 1"]

		if player1 and player2 and player1.Character and player2.Character then
			local rootPart1 = player1.Character:FindFirstChild("HumanoidRootPart")
			local rootPart2 = player2.Character:FindFirstChild("HumanoidRootPart")

			local spawnFolder = Workspace["Fighting Map 1"]["Spawn Locations"]
			local spawnParts = spawnFolder:GetChildren()

			-- Randomly select two different spawn points
			local randomSpawn1 = spawnParts[math.random(1, #spawnParts)]
			local randomSpawn2 = spawnParts[math.random(1, #spawnParts)]

			-- Ensure players don't spawn at the same location
			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.HealthChanged:Connect(function()
				if humanoid1.Health == 0 or humanoid2.Health == 0 then
					rootPart1.CFrame = Workspace.SpawnLocation.CFrame
					rootPart2.CFrame = Workspace.SpawnLocation.CFrame
					fighting.Value = false
				end
			end)
		end
	end
end)

It could be due to the part of script that are not running since it fires when certain conditions are met. So, try print() under things that fires.

1 Like

The fighting was enabled and I checked in game and also with a print statement.

Do you know which part isn’t working?

There are no errors shown anywhere in the output and the fighting is set as false when the server loads in.

I changed the if statement to if player1:FindFirstChild("Character") and player2:FindFirstChild("Character") then and got the following error:

19:40:34.445 ServerScriptService.Fight Requests Managers.Set 1.Fighting Manager:16: attempt to index nil with ‘FindFirstChild’ - Server - Fighting Manager:16

That means player1 or player2 doesn’t exist.

1 Like

so how do I deal with this issue?

Its something to do with this im guessing, print value1 and value2 and see what it shows

1 Like

You could use :WaitForChild and print the values to see if they’re niled.

1 Like

They show the corresponding usernames.

Is it because I’m storing the usernames as strings and they have to be converted?

I thought you couldnt do :FindFirstChild("Character") because character isnt a child of the player

1 Like

instead do..

if (player1.Character and player2.Character) then

1 Like

did exactly as you said and got the following error:

15:30:07.197 ServerScriptService.Fight Requests Managers.Set 1.Fighting Manager:16: attempt to index nil with ‘Character’ - Server - Fighting Manager:16

I fixed it by moving the variables value1 and value2 to inside the function

Thanks for the help to whoever replied! Always appreciate it :slight_smile:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.