Having Multi Script Debounce Issues

I’m trying to make it so that my scripts have a proper debounce, so that when my player touches a part with a specific name, it trips and “Ragdolls” with consistent results, but despite having multiple “debounces”, I’m running into issues.

To achieve the tripping effect, I have a local script in StarterCharacterScripts that detects when a player’s Humanoid touches a part with the name “Ragdoll_Initiate_Part_Code1”. When it detects that a player has touched that, it initiates another local script to cause the player to ragdoll. Both that and the script work fine, but I can’t find out how to debounce them properly. The debounce is not stopping my local scripts to not initiate their onTouched events. This is causing my FireServer event to not function properly and not have consistent results in causing the player to trip.

  1. Attempted Solutions
    So far, I’ve tried multiple Debounce methods, including creating a separate bool value and if statement, disabling CanTouch, and chaning the parts name for what the detection system is based off of.
    To activate these, I’ve created a separate global/regular script inside the triggering part.

  2. More information
    Here is my StarterCharacterScripts code that Fires the ragdoll script. The firing part is working fine, its just doing it way to often and potentially causing lag.

local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
local Player = game:GetService("Players").LocalPlayer
local RagdollRemote = Player:WaitForChild("RagdollRemote")

humanoid.Touched:Connect(function(hit)
	if hit.Name == "Ragdoll_Initiate_Part_Code1" then
		print("Character touched to Ragdoll Part")
		if game.Workspace.Ragdoll_Initiators_Debounce.Debounce.Value == false then
			RagdollRemote:FireServer(true)
		print("Player Ragdolled")
		wait(1)
		end
	end
end)

Here is my global/regular script situated inside the Ragdoll_Initiate_Part_Code1. The code works, but its not stopping the local StarterCharacterScript from activating too often.

function onTouched(hit)
	script.Parent.Name = "Ragdoll_Initiated_Part_Code2"
	script.Parent.CanTouch = false
    game.Workspace.Ragdoll_Initiators_Debounce.Debounce.Value = true
	print("Initiated")
	wait(2)
	script.Parent.Name = "Ragdoll_Initiate_Part_Code1"
	script.Parent.CanTouch = true
	game.Workspace.Ragdoll_Initiators_Debounce.Debounce.Value = false

end

connection = script.Parent.Touched:connect(onTouched)

I’ve also created a video showcasing what is happening. Please forgive me for the potato quality… its to help lower the file size.
If you look closely you can see that the codes are printing the same thing over and over again meaning they get activated more than once. This is causing my player to glitch out or not have consistent results with being tripped.

The explosion is merely cosmetic. It does not do damage to the player. It is activated in another script, which works fine.

Do you all have any idea what could be the issue? Thanks.

Try this:

local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
local Player = game:GetService("Players").LocalPlayer
local RagdollRemote = Player:WaitForChild("RagdollRemote")
local debounce = false

humanoid.Touched:Connect(function(hit)
	if hit.Name ~= "Ragdoll_Initiate_Part_Code1" then return end
	print("Character touched to Ragdoll Part")
	
	if debounce then return end
	debounce = true
	print("Player Ragdolled")

	RagdollRemote:FireServer(true)
	task.wait(1)
		
	debounce = false
end)

I don’t think you need the server script so just disable it (from it’s properties), this should be enough.

1 Like

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