so this code gives me the error infinite yield possible but the problem is i kinda need to keep the code inside a loop because the function that fires it requires a loop is there a way to rewrite it so it works inside a loop or a way to fire it from inside the loop?

while true do 
   local ReplicatedStorage = game:GetService("ReplicatedStorage")
   local hope = Instance.new("RemoteEvent")
   hope.Parent = game.ReplicatedStorage
   hope.Name = "hope"
   game.Players.PlayerAdded:Connect(function(plyr)
       local playerToKill = plyr
       hope:FireClient(plyr,playerToKill)
   end)
end  

here is the other code its messy i know but it works till the fireing of the remote event

local players = game:getService("Players")
local repStorage = game:GetService("ReplicatedStorage")
local remote = repStorage:WaitForChild("RemoteEventTest")
local work = false

				

players.PlayerAdded:Connect(function(player)

    player.CharacterAdded:Connect(function(character)

    
		while true do 
			local ReplicatedStorage = game:GetService("ReplicatedStorage")
            local hope = Instance.new("RemoteEvent")
            hope.Parent = game.ReplicatedStorage
            hope.Name = "hope"
            game.Players.PlayerAdded:Connect(function(plyr)
	            local playerToKill = plyr
                hope:FireClient(plyr,playerToKill)
            end)
			local test = (character:WaitForChild("HumanoidRootPart").Position - workspace.Hello.Position).Magnitude
			print(test)
			wait(1)
			remote.OnServerEvent:connect(function(player, request, ...)
	        request = request:lower()
	
	       if request == "serverprint" then
		
		        print("it recived")
		        local work = true
			    print(work)
		        if test < 20 then
						
				        print("reeeee")
				        print(work)
				
				        if work == true then 
					
							print("that worked????")
							
				        end
				        print("1")
		
	          
				
		       end

		
	       end
	
	       if request == "oof" then
		
				    print("it closed")
					local work = false
		
        
		
	       end
        end)
			
		end


  end)

end)

4 comments

0

Why are you creating an absurd amount of Remotes?

0

I agree, just fire an "absurd" amount, don't constantly create it

0

Hmmm why is the players added event inside a loop? There is no need, for it will run whether it is in a loop or not. Also, when you write hope.Parent, just write replicated storage since the variable ha been made and making that many remotes is no good. Why does it have to be in a loop? Can you show that function?

0

yes its a bit messy ill put in edit to make it easier also thank you for your help so far