Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Humanoid:TakeDamage() not working properly?

Asked by 4 years ago
Edited 4 years ago

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:

1--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.
2script.Parent.Touched:Connect(function(t)
3    if t.Parent:FindFirstChild("Humanoid") then
4        t.Parent.Humanoid:TakeDamage(15)
5    end
6end)

script 2:

01--Variables may be confusing, so I will give context. (if it helps, this is a server script in serverscriptservice)
02local tchfx = game.ReplicatedStorage:WaitForChild("ThunderCharge") --The damage part
03local Elfx = game.ReplicatedStorage:WaitForChild("ElectricityFx") --This is just an effect for it
04 
05tch.OnServerEvent:Connect(function(p)
06    local c = p.Character
07    local hrp = c:FindFirstChild("HumanoidRootPart")
08    local tchfxc = tchfx:Clone()
09    local ElfxC = Elfx:Clone()
10    tchfxc.Parent = workspace -Putting damage part in workspace
11    hrp.Position = Vector3.new(hrp.Position.X,hrp.Position.Y * 2,hrp.Position.Z) --Putting                                          
12    tchfxc.Position = Vector3.new(hrp.Position.X,hrp.Position.Y,hrp.Position.Z) --Putting character higher in air
13        damage part where character is
14    hrp.Anchored = true --Making it so character doesn't move
15    wait(.25)
16    ElfxC.Position = Vector3.new(hrp.Position.X,hrp.Position.Y,hrp.Position.Z) --Putting effects where character is
17    ElfxC.Parent = workspace --Putting effects in workspace
18    ElfxC.Script.Disabled = false --Enablingscript inside of effect
19    tchfxc.Dmg.Disabled = false --Enabling damage script, which should make everything it touches do some damage
20end)

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.

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. papasherms 168 — 4y
0
it was a remote event from the client sent to the server, which then the server enabled the script. hihowareya115 53 — 4y
0
i didnt include the client script as that part was working fine hihowareya115 53 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

I found a solution that works for me

01local player = game.Players.LocalPlayer
02local debounce = false --the debounce is for a cooldown
03 
04script.Parent.Touched:Connect(function(hit)
05    if not debounce then
06        debounce = true
07        local character = hit.Parent
08        local Humanoid = character:FindFirstChildWhichIsA("Humanoid")
09        if Humanoid then
10            Humanoid.Health = Humanoid.Health-15 --change the number to how much health you want the player lose
11        end
12        wait(1) --change the number to how many seconds you want before it hurts you again
13        debounce = false
14    end
15end)

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

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. hihowareya115 53 — 4y
Ad

Answer this question