Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Humanoid:TakeDamage() not working properly?

I was working on a script for an ability, and I encountered an issue. In the script below, you will see I used script.Parent.Touched:Connect(function(t), however it didn't work. I tried the same exact script on a normal brick in workspace to see if I was crazy, and it worked. Here is my script:

--This is the damage script inside the damage part (script is disabled until activated in next script) if it helps, this is a server script.
script.Parent.Touched:Connect(function(t)
	if t.Parent:FindFirstChild("Humanoid") then
		t.Parent.Humanoid:TakeDamage(15)
	end
end)

script 2:

--Variables may be confusing, so I will give context. (if it helps, this is a server script in serverscriptservice)
local tchfx = game.ReplicatedStorage:WaitForChild("ThunderCharge") --The damage part
local Elfx = game.ReplicatedStorage:WaitForChild("ElectricityFx") --This is just an effect for it 

tch.OnServerEvent:Connect(function(p)
	local c = p.Character
	local hrp = c:FindFirstChild("HumanoidRootPart")
	local tchfxc = tchfx:Clone() 
	local ElfxC = Elfx:Clone()
	tchfxc.Parent = workspace -Putting damage part in workspace
	hrp.Position = Vector3.new(hrp.Position.X,hrp.Position.Y * 2,hrp.Position.Z) --Putting 											 
	tchfxc.Position = Vector3.new(hrp.Position.X,hrp.Position.Y,hrp.Position.Z) --Putting character higher in air
        damage part where character is
	hrp.Anchored = true --Making it so character doesn't move
	wait(.25)
	ElfxC.Position = Vector3.new(hrp.Position.X,hrp.Position.Y,hrp.Position.Z) --Putting effects where character is
	ElfxC.Parent = workspace --Putting effects in workspace
	ElfxC.Script.Disabled = false --Enablingscript inside of effect
	tchfxc.Dmg.Disabled = false --Enabling damage script, which should make everything it touches do some damage
end)

For even more context, Second script is a function called through client by pressing a key (that is working nicely, so that isn't part of the issue. The script DOES enable when the script runs, The parts do show up at the characters humanoidrootpart, But for some reason it does not damage.

3 comments

0

if you're enabling a script from a local script and that scripts job it to take damage to your humanoid, it will not work. It needs to be done on the server for it to register across the board.

0

it was a remote event from the client sent to the server, which then the server enabled the script.

0

i didnt include the client script as that part was working fine

1 answer

I found a solution that works for me

local player = game.Players.LocalPlayer
local debounce = false --the debounce is for a cooldown

script.Parent.Touched:Connect(function(hit)
	if not debounce then
		debounce = true
		local character = hit.Parent
		local Humanoid = character:FindFirstChildWhichIsA("Humanoid")
		if Humanoid then
			Humanoid.Health = Humanoid.Health-15 --change the number to how much health you want the player lose
		end
		wait(1) --change the number to how many seconds you want before it hurts you again
		debounce = false
	end
end)

This is a server script inside of the part that takes the damage.

1 comment

0

isnt working still, this is kinda just my script except instead of humanoid:takedamage() its humanoid.Health - humanoid.healh. As i said in my post, i tried the exact same script on a normal part and it worked, but when i take something out of replicated storage and enable its dmg script it doesnt work.

This discussion is preserved as it was. New answers, comments, and votes are closed.