You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
I would like to create a functional attack script, using a click detector
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.
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)
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)
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