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

Damage script not printing out the Player in workspace?

Asked by 3 years ago

Hello.

I am currently making a Damage script, that when you run into a specific NPC's HumanoidRootPart, it prints out the Player's character in workspace. This at times prints out the player, and at other times it prints out a hat they have. It's very unconsistant and I'm extremely confused about it and why it's happening. I've never ran into an issue like this before, and it;s very confusing.

My Script:

local Debounce = false
local NPC = script.Parent

local HumanoidRootPart = NPC.HumanoidRootPart

local Humanoid = NPC.Humanoid
local AnimationsFolder = NPC.Animations

local AttackAnimation = AnimationsFolder.Attack
local Animation = Humanoid.Animator:LoadAnimation(AttackAnimation)

HumanoidRootPart.Touched:Connect(function(Hit))
    if not (Debounce) then
        Debounce = true
        print(Hit.Parent)
        Animation:Play()
        wait(1)
        Debounce = false
    end
end)

If I could get help with this, it would be great. Thanks!

1 answer

Log in to vote
1
Answered by 3 years ago

Try add a check that the part that hit is a player's character

if game.Players:GetPlayerFromCharacter(Hit.Parent) and not Debounce then
    ...
end
0
Worked fantastically. Thanks! Will keep this in mind next time. Had forgotten about the GetPlayerFromCharacter part. Thanks alot! RazzyPlayz 497 — 3y
Ad

Answer this question