Need some help with my attack scriot

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I would like to create a functional attack script, using a click detector

  2. What is the issue? Include screenshots / videos if possible!
    The clickdetector works I think, as the click cursor appears but nothing happens, no animation is played and no health is depleted.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I’ve tested it in studio (testing using a local server) and in game, there are no errors, I tweaked it, still didn’t work. I would’ve searched up the problem but I don’t know what’s gone wrong.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

The script is a serverscript, it and the clickdetector are both children of the humanoidrootpart of my model. If you need more info please ask.

local EnemyPart = script.Parent
local EnemyChar = EnemyPart.Parent
local EnemyHum = EnemyChar.Humanoid

local CD = EnemyPart.ClickDetector


CD.MouseClick:Connect(function(player)
	local AttackAnim = script:WaitForChild("Attack")

	local Character = player.Character
	local Animator = Character.Humanoid:WaitForChild("Animator")

	local AttackTrack = Animator:LoadAnimation(AttackAnim)


	if EnemyHum.Maxhealth > 20 then
		AttackTrack:Play()
		EnemyHum.MaxHealth = EnemyHum.MaxHealth - 10
	end
end)

Could you try debugging it with print() statements? I believe your script should work fine, but do double-check that everything should work hopefully?

Also make sure the animation is owned by you

It didn’t print anything in the output and the animation is made by me.

local EnemyPart = script.Parent
local EnemyChar = EnemyPart.Parent
local EnemyHum = EnemyChar.Humanoid

local CD = EnemyPart.ClickDetector

print("Script loading")

CD.MouseClick:Connect(function(player)
    print("Event fired")
	local AttackAnim = script:WaitForChild("Attack")

	local Character = player.Character
	local Animator = Character.Humanoid:WaitForChild("Animator")

	local AttackTrack = Animator:LoadAnimation(AttackAnim)


	if EnemyHum.Maxhealth > 20 then
        print("Found a valid enemy")
		AttackTrack:Play()
		EnemyHum.MaxHealth = EnemyHum.MaxHealth - 10
    else
        print("Invalid")
	end
end)

Try this?

oh ill try that then and see if it works.

nope nothing is printed in the output.

Okay but how though

Chances are there’s probably an error, or your script is disabled? At the very least, the first print() statement would work regardless since nothing’s encased inside it O_o

Are you sure that you have your Output open…?

Its weird right? I have Output on standby, the script is enabled too.

Try parenting the ClickDetector to the head and see if that changes anything?

1 you are not using remote events and 2 load the animation from the humanoid.
(nevermind just read that it is from a serverscript)

i think the problem is that im using a custom character, the scripts that are loaded in are in the startercharacter scripts.

Yes! I tweaked the variables a bit and put it in startercharacterscripts! It prints in the output!! Thx for the help!

Oh that would explain it then, at least the issue got fixed! :sweat_smile: