Most efficient way to make a bleed system?

I can’t even select any of the errors to bring me to the code that is causing this issue, I don’t know why.

Lol wait, I just noticed that I used Touched event twice.

local debounce = false
game.Workspace.Tutorial.Touched:Connect(function(hit)
    if debounce == false then
        debounce = true

        local module = require(game.ReplicatedStorage.ModuleScript)
 
        module.Bleed(hit.Parent:WaitForChild("Humanoid"))

        debounce = false
    end
end)

That’s why it was printing there is no function in the second Connect function. This should work now.

1 Like

Oh I thought that was intentional, well it works. Thank you! I just need to implement this into my game!

1 Like

This doesn’t work in my place. I disabled the health core gui, so that might be the problem, I’ll go check if that is the problem.

EDIT: I added back the health core gui, and still it didn’t work.

Do you still have any errors in the output?

No, I have no errors, also thank you for the fast reply.

1 Like

Uhm, I might have forgot to change the dots to colons after

This may be module:Bleed

function BleedModule.Bleed(humanoid)

and this BleedModule:Bleed

I’m sorry because this is the first time I wrote a module script.

EDIT: @Babybunnyiscute19 I’m going to test it in the published one.

I copied and pasted all of the code from the other test place to my main place and it didn’t work. It worked in the test place, but not in the main place.

Wait, did you say you copied the whole script without adjusting it? Did you change the name of the parts like

game.Workspace.Tutorial

And the scripts work perfectly for me.

I changed it from game.Workspace.Tutorial to script.Parent and it worked in the test place, but when I move it to the main game, it doesn’t work. I will change the name though.

EDIT: I copied and pasted the exact character (the part is attached to the body of an npc), and it still didn’t work.

Weird. I don’t think there is an issue with the script but the part you are touching or the parent of the script. Make sure you are touching that part and the script is parented to the part and its type is Script.

Screenshot 2021-04-28 161149
That script has the on touched functions.
I don’t know how it’s not working, but it’s not.

I also tried it on an NPC. It worked for me. Maybe because of its anchored property. So when it drops off you are not able to touch it? Or can you please check you are touching the correct part with a code?

script.Parent.Touched:Connect(function()
    print("ok")
end

Edit: I’m really sorry, but I couldn’t solve this issue. I’m out of ideas except one. Do you have a warn called infinite yield possible?

I used this code because the torso is touching the detection part:

script.Parent.Touched:Connect(function(hit)
	local hitT = hit.Parent:GetChildren()
	for i,v in pairs(hitT) do
		if v:IsA("LocalScript") then
			if v.Name == "BloodFlash" then
				print("e")
			end
		end
 	end
end)

It prints e

I think I figured out why it’s not working. The game uses sound regions to play certain music when you are in the region. This might be affecting the way the module script works.

EDIT: That is what was causing it, but the detection part is VERY unreliable. The detection part is cancollide false, because that is the area where you take damage when being attacked by an enemy. This makes the script very hard to use and most of the time, the bleed system doesn’t even work.

Do you know of a way to make to fix this? I certainly don’t. Is it possible to use collision groups to make this work? I’d assume that it’d very tedious.

1 Like

I found a small fix, If I turn CanTouch off, the music, and fog both play, but the npc can hit me, but only once.

EDIT: The fog doesn’t show when you walk into the region, but the sound still plays.

EDIT2: I am thinking of removing the module script in place of using that same function in each part, I will use this module for another game.