event:FireServer and event.OnServerEvent doesn't work

when I fire a event, the server doesn’t recieve it!

client code:

wait(7)
game.ReplicatedStorage.Events.StartEvent.OnClientEvent:Connect(function()
   print("started")
   script.Parent.Frame.Visible = true
   script.Parent.Value.Value = true
   wait(10)
   script.Parent.Frame.Visible = false
   script.Parent.Value.Value = false
end)

script.Parent.Frame.TextButton.MouseButton1Click:Connect(function()
   
   if script.Parent.Value.Value == true then
   	script.Parent.Frame.Visible = false
   	script.Parent.Value.Value = false
   	game.ReplicatedStorage.Events.EnterPlayer:FireServer()
   	
   end
   
end)

server code:

game.ReplicatedStorage.Events.EnterPlayer.OnServerEvent:Connect(function(plr)
	print(plr)
	
		
		
		table.insert(plrs,plr.Name)
		game.Workspace.Obby.End.Touched:Connect(function(h)
			
			if h.Parent and h:FindFirstChild("Humanoid") then
				local winner = game.Players:GetPlayerFromCharacter(h.Parent)
				winner.leaderstats.Kimchi += 1500
				workspace.Obby.Barrier.Transparency = 0.5
				workspace.Obby.Barrier.CanCollide = true
				for index,value in ipairs(plrs) do
					
					if game.Players[value] then
						
						game.Players[value].Character.Humanoid.Health = 0
						
					end
					
				end
				
			end
			
		end)
		
		
	
	
end)
1 Like

oh yeah, it doesn’t print “plr”

this is for the chars

Is the value true?
Is there any code before the actual OnServerEvent?

yes,


while true do
	
	wait(10)
	game.ReplicatedStorage.Events.StartEvent:FireAllClients()
	
	print("yes")
	wait(10)

	workspace.Obby.Barrier.Transparency = 1
	workspace.Obby.Barrier.CanCollide = false
	
	print('start')
	wait(180)
end

game.ReplicatedStorage.Events.EnterPlayer.OnServerEvent:Connect(function(plr)
	print(plr)
	
		
		
		table.insert(plrs,plr.Name)
		game.Workspace.Obby.End.Touched:Connect(function(h)
			
			if h.Parent and h:FindFirstChild("Humanoid") then
				local winner = game.Players:GetPlayerFromCharacter(h.Parent)
				winner.leaderstats.Kimchi += 1500
				workspace.Obby.Barrier.Transparency = 0.5
				workspace.Obby.Barrier.CanCollide = true
				for index,value in ipairs(plrs) do
					
					if game.Players[value] then
						
						game.Players[value].Character.Humanoid.Health = 0
						
					end
					
				end
				
			end
			
		end)
		
		
	
	
end)

That should be why use this:

spawn(function()
	while true do
		
		wait(10)
		game.ReplicatedStorage.Events.StartEvent:FireAllClients()
		
		print("yes")
		wait(10)
	
		workspace.Obby.Barrier.Transparency = 1
		workspace.Obby.Barrier.CanCollide = false
		
		print('start')
		wait(180)
	end
end)

oh yee tysm i forgot the loops ran forever like that

Or just move the loop below the event connection (better for memory).

1 Like