To make it so that clicking on the Stick part of the StarterCharacter model deals damage and increases a Leaderstats value, you can add some code to your onInputBegan
function. Here’s an example:
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)
-- Check if the mouse click hit the Stick part
local mouseHit = UserInputService:GetMouseLocation()
local ray = workspace:Raycast(mouseHit.UnitRay.Origin, mouseHit.UnitRay.Direction * 100)
if ray and ray.Instance == Character.Stick then
-- Deal damage to the player who clicked
local clickedPlayer = game.Players:GetPlayerFromCharacter(Character)
local clickedHumanoid = Character:FindFirstChildOfClass("Humanoid")
if clickedPlayer and clickedHumanoid then
clickedHumanoid:TakeDamage(10)
-- Increase Leaderstats value by 1
local leaderstats = clickedPlayer:FindFirstChild("leaderstats")
if leaderstats then
local clicks = leaderstats:FindFirstChild("Clicks")
if clicks then
clicks.Value = clicks.Value + 1
end
end
end
else
-- Play animation if the mouse click did not hit the Stick part
Anim:Play()
wait(0.8)
end
debounce = false
end
end
In this code, we first check if the mouse click hit the Stick part using a Raycast. If it did, we get the player who clicked and their Humanoid, and use the TakeDamage()
method to deal damage to the player. We then check if the player has a Leaderstats folder, and if so, find the Clicks value and increase it by 1. If the mouse click did not hit the Stick part, we simply play the animation as before. Note that the animation will still play even if the mouse click hits the Stick part, so you may want to modify the code to prevent this if desired. Hope this helps x