Hello, i made this script that if you click, it plays and animation. But i have a custom StarterCharacter model with a Stick part in it, how do i make it that if someone touches the stick part when clicked, it deals them damage and makes adds one to a leaderstats value
local UserInputService = game:GetService("UserInputService")
local Animation = script.Stick
local debounce = false
local function onInputBegan(input, _gameProcessed)
if input.UserInputType == Enum.UserInputType.MouseButton1 and debounce == false then
debounce = true
print("The left mouse button has been pressed!")
local Player = game. Players. LocalPlayer
local Character = Player. Character
local Humanoid = Character :WaitForChild ("Humanoid")
local Anim = Humanoid: LoadAnimation (Animation)
Anim:Play()
wait(0.8)
debounce = false
end
end
UserInputService.InputBegan:Connect(onInputBegan)
local stick = game.Players.LocalPlayer.Character.Stick
local damage = 10
stick.Touched:Connect(function(hit)
if hit.Parent =~ stick.Parent and debounce == false then
local h = hit.Parent:FindFirstChildOfClass("Humanoid")
if h then
h.Value -= damage
end
end
end)
Im giving the full thing as you’re a beginner. You should always avoid copy pasting and try writing yourself using the logic as that’s better to learn.
If you are looking to create an hitbox system, you might wanna have the part where the damage is applied handled on the server to avoid future issues and possible exploits.
If you kill an humanoid on your client only, it could cause potential issues such as a desynchronisation between what you see and what they see.
If a feature is mentioned as deprecated, it doesn’t necessarily means it’s un-usable.
I just tested on a baseplate and LoadAnimation() still works. Deprecated only means that the feature you are using is outdated and that more efficient alternatives are available.