Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do i make a combat script so that when i press Q it punches?

Ok, so i was wondering how i make a combat script for my anime game me and my friends are working on! i was wondering how to do it cause i'm really not sure on how to! Also, what is the best way to learn how to make projectile scripts like kamehamehas, melee scripts like combat, and how to make GUI shops for my gamepasses?!

1 answer

#User Input

First off, you would want to get input from the player. In this case, you want the character to punch when Q is pressed. That would be implemented something like this in a local script:

Using UserInputService:

local UserInputService = game:GetService("UserInputService")
UserInputService.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.Q then
		--Make the character punch
	end
end)

Using ContextActionService:

local ContextActionService = game:GetService("ContextActionService")
function qPressed ()
	--Make the character punch
end
ContextActionService:BindAction("qPressed" , qPressed , false , "q")

UserInputService: http://wiki.roblox.com/index.php?title=API:Class/UserInputService ContextActionService: http://wiki.roblox.com/index.php?title=ContextActionService_tutorial

#Animations

After you have the input, you need the character to punch. In order to to do this, first make or find an animation for punching. You can learn how to make your own animation here: http://wiki.roblox.com/index.php?title=Animations

In order to play the animation, you would insert an Animation object under workspace. Set the AnimationID to the animation you want to be played. Then do something like this to play the animation in a local sript:

--Variables
local animation = workspace.Animation --Replace with path to your own animation
local player = game.Players.LocalPlayer
local char = player.character or player.CharacterAdded:wait()
local humanoid = char:WaitForChild("Humanoid")

--Load animation
local animTrack = humanoid:LoadAnimation(animation)

Now in order to play the animation you could do animTrack:Play().

#Damage

Now because you are creating a combat game, I assume that you want the punch to deal damage of some sort. This part is highly dependent on your implementation of your game but one way would be to detect the person attacked whenever the player punches through a touched event. Then you would fire a remote event telling the server (remember this is from a local script) to validate and damage the player punched. You can read about remote events here: http://wiki.roblox.com/index.php?title=Remote_Events_and_Functions

These ideas should give you something to get started. If you have any questions, feel free to comment below!

2 comments

0

Thanks for this but it kinda confused me, i'm sorry.. i'm new to scripting and im making a DBZ game.. i'm trying my best to learn and im not sure what the best way to learn this stuff is

0

If you are new to scripting you might want to step back a little first. Start simple and work your way up.

This discussion is preserved as it was. New answers, comments, and votes are closed.