CERTAIN LOCALSCRIPTS NOT WORKING - Events not firing?

image
This was the original, however now it’s just some tweening

That is really bad practice. It is unreliable, and is not a proper fix.

Please provide the rest of the code so we can see what you’re doing. Supplying only part of the code that you’re having trouble with won’t help either you or anyone trying to help you.

Try putting the FireAllClients() in a while loop, and see if that works (for testing, not for practical use)

Tried it and yep, that works in a normal plain loop

Originally didn’t plan on posting it, but here:

while true do wait(1)
–pcall(function()
–print(“looping”)

local AllPlayers = {}
for i,v in pairs(game.Players:GetPlayers()) do
	--print(v)
	table.insert(AllPlayers, #AllPlayers + 1, v)
end

if 2 <= #AllPlayers then
	--print(#AllPlayers)
	--print("starting round!")



	for i,v in pairs(game.Players:GetPlayers()) do
		local CouldFight = {}
		if v.Information.CurrentlyAFK.Value == false then
			if v.Information.InMatch.Value == false then
				if v.Information.Died.Value == false then 


					for k,z in pairs(game.Players:GetPlayers()) do
						if z ~= v then
							wait()
							if z.Information.CurrentlyAFK.Value == false then
								if z.Information.InMatch.Value == false then
									if z.Information.Died.Value == false then
										if z.Character then
											table.insert(CouldFight, #CouldFight + 1, z)
										end
									end
								end

							end
						end
					end
				end


				if #CouldFight >= 1 then
					local Picker = math.random(1, #CouldFight)


					local Player1 = v
					local Player2 = CouldFight[Picker]
					
					if game.Workspace:FindFirstChild(tostring(Player2)) and game.Workspace:FindFirstChild(tostring(Player1)) then
						local Arenaz = nil
						local AvArenas = {}

						for i,v in pairs(game.ServerStorage.Arenas:GetChildren()) do
							if v.Active.Value == false then
								table.insert(AvArenas, #AvArenas + 1, v.Name)
							end
						end


						Arenaz = AvArenas[math.random(1, #AvArenas)]
						game.ServerStorage.Arenas[Arenaz].Active.Value = true
						
						local Sword = game.ServerStorage:FindFirstChild("Sword")
						
						if not game.Players[tostring(Player1)]:WaitForChild("Backpack"):FindFirstChildWhichIsA("Tool") then
							Sword:Clone().Parent = game.Players[tostring(Player1)]:WaitForChild("Backpack")
						end
						
						if not game.Players[tostring(Player2)]:WaitForChild("Backpack"):FindFirstChildWhichIsA("Tool") then
							Sword:Clone().Parent = game.Players[tostring(Player2)]:WaitForChild("Backpack")
						end
								
						game.Players[tostring(Player1)]:WaitForChild("Information").Hostile.Value = Player2
						game.Players[tostring(Player2)]:WaitForChild("Information").Hostile.Value = Player1
						
						game.Players[tostring(Player1)].Character.Humanoid.Health = 100
						game.Players[tostring(Player2)].Character.Humanoid.Health = 100

						game.Players[tostring(Player1)]:WaitForChild("Information").Arena.Value = Arenaz
						game.Players[tostring(Player2)]:WaitForChild("Information").Arena.Value = Arenaz

						game.Players[tostring(Player1)]:WaitForChild("Information").InMatch.Value = true
						game.Players[tostring(Player2)]:WaitForChild("Information").InMatch.Value = true
						
						game.Players[tostring(Player1)].Character:FindFirstChild("Humanoid").WalkSpeed = 0
						game.Players[tostring(Player2)].Character:FindFirstChild("Humanoid").WalkSpeed = 0

						game.Players[tostring(Player1)].Character:FindFirstChild("HumanoidRootPart").CFrame = game.Workspace[Arenaz].Team1Spawn.CFrame
						game.Players[tostring(Player2)].Character:FindFirstChild("HumanoidRootPart").CFrame = game.Workspace[Arenaz].Team2Spawn.CFrame
						

						wait(1)
						print("before event firing")
						Events.MatchInfo:FireAllClients("3", "2", "1", "Begin", tostring(Player1))
						print("after event firing")
						
						

						--Events.MatchInfo:FireAllClients()
						
						

						
						delay(4, function()
							game.Players[tostring(Player1)].Character:FindFirstChild("Humanoid").WalkSpeed = 16
							game.Players[tostring(Player2)].Character:FindFirstChild("Humanoid").WalkSpeed = 16
						end)
					end
				end
			end
		end
	end
else
	--print("Need more to start!")
end
--end)

end

The firing can be found right at the bottom, near the end

still not solved?? ill try to help to the limits of my abilities!!

1 Like

try adding more prints to see which line it stops on?? try that cuz i dont see them here, in the whole script…

Doesn’t stop at all just ignores the entire fire function, it’ll continue fine before the attempted fire and after the fire too

1 Like

hmm weird… can you show me the code? (srry im missing out lol)

The code, right here;
The client is just a print, I think the issue is on the server than the client.

while true do wait(1)
–pcall(function()
–print(“looping”)

local AllPlayers = {}
for i,v in pairs(game.Players:GetPlayers()) do
	--print(v)
	table.insert(AllPlayers, #AllPlayers + 1, v)
end

if 2 <= #AllPlayers then
	--print(#AllPlayers)
	--print("starting round!")



	for i,v in pairs(game.Players:GetPlayers()) do
		local CouldFight = {}
		if v.Information.CurrentlyAFK.Value == false then
			if v.Information.InMatch.Value == false then
				if v.Information.Died.Value == false then 


					for k,z in pairs(game.Players:GetPlayers()) do
						if z ~= v then
							wait()
							if z.Information.CurrentlyAFK.Value == false then
								if z.Information.InMatch.Value == false then
									if z.Information.Died.Value == false then
										if z.Character then
											table.insert(CouldFight, #CouldFight + 1, z)
										end
									end
								end

							end
						end
					end
				end


				if #CouldFight >= 1 then
					local Picker = math.random(1, #CouldFight)


					local Player1 = v
					local Player2 = CouldFight[Picker]
					
					if game.Workspace:FindFirstChild(tostring(Player2)) and game.Workspace:FindFirstChild(tostring(Player1)) then
						local Arenaz = nil
						local AvArenas = {}

						for i,v in pairs(game.ServerStorage.Arenas:GetChildren()) do
							if v.Active.Value == false then
								table.insert(AvArenas, #AvArenas + 1, v.Name)
							end
						end


						Arenaz = AvArenas[math.random(1, #AvArenas)]
						game.ServerStorage.Arenas[Arenaz].Active.Value = true
						
						local Sword = game.ServerStorage:FindFirstChild("Sword")
						
						if not game.Players[tostring(Player1)]:WaitForChild("Backpack"):FindFirstChildWhichIsA("Tool") then
							Sword:Clone().Parent = game.Players[tostring(Player1)]:WaitForChild("Backpack")
						end
						
						if not game.Players[tostring(Player2)]:WaitForChild("Backpack"):FindFirstChildWhichIsA("Tool") then
							Sword:Clone().Parent = game.Players[tostring(Player2)]:WaitForChild("Backpack")
						end
								
						game.Players[tostring(Player1)]:WaitForChild("Information").Hostile.Value = Player2
						game.Players[tostring(Player2)]:WaitForChild("Information").Hostile.Value = Player1
						
						game.Players[tostring(Player1)].Character.Humanoid.Health = 100
						game.Players[tostring(Player2)].Character.Humanoid.Health = 100

						game.Players[tostring(Player1)]:WaitForChild("Information").Arena.Value = Arenaz
						game.Players[tostring(Player2)]:WaitForChild("Information").Arena.Value = Arenaz

						game.Players[tostring(Player1)]:WaitForChild("Information").InMatch.Value = true
						game.Players[tostring(Player2)]:WaitForChild("Information").InMatch.Value = true
						
						game.Players[tostring(Player1)].Character:FindFirstChild("Humanoid").WalkSpeed = 0
						game.Players[tostring(Player2)].Character:FindFirstChild("Humanoid").WalkSpeed = 0

						game.Players[tostring(Player1)].Character:FindFirstChild("HumanoidRootPart").CFrame = game.Workspace[Arenaz].Team1Spawn.CFrame
						game.Players[tostring(Player2)].Character:FindFirstChild("HumanoidRootPart").CFrame = game.Workspace[Arenaz].Team2Spawn.CFrame
						

						wait(1)
						print("before event firing")
						Events.MatchInfo:FireAllClients("3", "2", "1", "Begin", tostring(Player1))
						print("after event firing")
						
						

						--Events.MatchInfo:FireAllClients()
						
						

						
						delay(4, function()
							game.Players[tostring(Player1)].Character:FindFirstChild("Humanoid").WalkSpeed = 16
							game.Players[tostring(Player2)].Character:FindFirstChild("Humanoid").WalkSpeed = 16
						end)
					end
				end
			end
		end
	end
else
	--print("Need more to start!")
end
--end)

end

1 Like

extra thing: is the script client sided or server sided?

The script I posted is server sided

1 Like

So it works? If so, try to run FireAllClients when the player clicks a button or something, e.g:

-- parent this to a text button or something
local RPS = game:GetService("ReplicatedStorage")
local event = RPS.Events.TriggerMatchInfo -- just make a new remote event and name it to this
local button = script.Parent
button.Activated:Connect(function()
    event:FireServer()
end)

-- Server
local RPS = game:GetService("ReplicatedStorage")
local event = RPS.Events.TriggerMatchInfo -- just make a new remote event and name it to this
local event2 = RPS.Events.MatchInfo
event.OnServerEvent:Connect(function(plr) -- at this point client should be fully loaded in
    event2:FireAllClients() -- test if client works
end)

Yep that works, I believe the issue is something to do with my loop above.

I think the server is firing the event before the client has connected to it.

The server can only fire the event once the client has confirmed it to do so (aka there’s a button named AFK, if off it the entire server-script will ignore, else it’d include the client, so normally after loading in I’ll wait 4-5 seconds before turning AFK off.

UPDATE

After some tests, it seems as if only certain LocalScripts are working.
I am still extremely confused, a script such as a simple print(“hello”) fails to print, while the script is located in StarterGui, under a ScreenGui and is not disabled.
This literally is driving me insane and preventing all work on my current project :\

output

where it’s located (it’s ‘LocalScript’)
image

contents of local script
image

I am clicking play with character to test