Trying to making an execution system for a roguelike game

  1. I’m trying to make a system that detects a knocked player to execute but the way i’m doing it doesn’t work really well. Any suggestions/help?

  2. Sometimes I see the execute text when I’m walking away from the player and the text is still here

  3. As you can see in my code I tried running a loop

task.spawn(function()
	while Hum.Health > 0.01 do task.wait(Settings.WAIT_TIME) -- While the player is in an alive state keep searching for a player that can be gripped
		if Hum.Health <= 0.01 or Possible or isGripping then return end -- If there is a possible player in range then hold up
		for _, PossiblePlr in Players:GetPlayers() do
			print("Looking for a player that can get executed")
			if PossiblePlr:IsA("Player") then print("Client might of found a player") -- Confirm if the typeof value is a Player (will be changed for NPCs later in development)
				if PossiblePlr.Character["IsKnocked"].Value and Hum.Health > 0.01 and PlrTable:CheckConditions("canGrip") and (Root.Position - PossiblePlr.Character.PrimaryPart.Position).Magnitude <= Settings.GRIP_MAG and not isGripping then -- Self-explainatory
					Possible = true
					GripUi.Enabled = true
					CanGrip:InvokeServer(PossiblePlr.Character, Settings.GRIP_MAG)
					--else
					--	Possible = false
					--	GripUi.Enabled = false
					print(Possible)
					if CanGrip and PossiblePlr.Character["IsKnocked"].Value and Hum.Health > 0.01 and PlrTable:CheckConditions("canGrip") and (Root.Position - PossiblePlr.Character.PrimaryPart.Position).Magnitude <= Settings.GRIP_MAG and Possible and not isGripping then
						print(Possible)
						Possible = true
						print("table insert")
						CanGrip = nil
					else
						CanGrip = false
						GripUi.Enabled = false
						warn("Error while process.")
						Possible = false
						--return
					end
				end
			end
		end
	end
end)
2 Likes

Your code needs a way to reset if gripping is possible. You can for example create a variable for number of grip targets, and if after looping through all the players it is 0, then there is no one to grip and you can safely hide your GUIs.

Let me know if that helps you get started :smiley:

1 Like

I’ll try doing that actually, thank you :pray: