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

Damage script not printing out the Player in workspace?

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

✓ Accepted answer

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

1 comment

0

Worked fantastically. Thanks! Will keep this in mind next time. Had forgotten about the GetPlayerFromCharacter part. Thanks alot!

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