You can write your topic however you want, but you need to answer these questions:
- What do you want to achieve? Keybind with animation and damage when tool equipped
You can write your topic however you want, but you need to answer these questions:
heres how to play an animation when pressing a key
local UIS = game:GetService("UserInputService")
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
repeat task.wait() until Player.Character
UIS.InputBegan:Connect(function(key,gpe)
if gpe then return end
if key.KeyCode == Enum.KeyCode.E then -- change "E" to any key you want
local anim = Instance.new("Animation")
anim.AnimationId = "rbxassetid://..." -- add ur animationid
local loadAnim = Character.Humanoid:LoadAnimation(anim)
loadAnim:Play()
anim:Destroy()
end
end)
now you mentioned you also want to damage when the tool is equipped, that would take a bit more time depending on how good you want the damaging system to be and how you even want it to be cause you didnt mention if you want it to damage the player or an enemy. For damaging someone else you would need to make a whole hitbox system and then from that you can use it to damage others. Try to learn how to code cause this is simple stuff and you should be able to make it yourself.
Here are some things that can help you:
Example:
Character.ChildAdded:Connect(function(Child)
if Child:IsA("Tool") then
HasToolEquipped = true
end
end)
You can then do the same thing except using “ChildRemoved” instead of “ChildAdded” and setting the variable to false instead of true.
You have a choice to make now. You can either use “ContextActionService” or “UserInputService” to do something when a certain key is pressed. I would recommend researching these services as it would help you with this project and help in the future.
Taking damage is not that tricky, You can use “Humanoid.Health -= Damage” (Humanoid being a child of the character and Damage being the amount you damage. Just to let you know -= is the same as doing Humanoid.Health = Humanoid.Health - Damage just more simpler).
Playing an animation is simple, I would recommend researching this as well. Roblox has a documentation site which covers everything I think. If you want to play an animation for someting that has a “Humanoid” you would just need to create an animation through “Instance.new” then set the animation Id. You would then need to load the animation through the already existing “Animator” which is a child of the Humanoid. Then you would simply play it when wanted.
You should also research online before making a post as you may be able to find the answer floating around somewhere.
Documentation:
I wish you the best of luck with your projects, cya! - Kotium_I
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.