Como criar um Soco no Roblox Studio

Como Criar Soco 2.0 no Roblox Studio

Quer deixar seu jogo no Roblox Studio ainda mais dinâmico e divertido? Neste tutorial, vou te mostrar como criar um soco 2.0 no Roblox Studio, onde a mão do personagem cresce no momento do impacto, causando dano e empurrando objetos e inimigos! 💥

Se você já sabe o básico de programação em Lua e quer aprimorar suas habilidades no Roblox Studio, essa aula é perfeita para você. Vamos utilizar RemoteEvents, TweenService e BodyVelocity para criar um efeito de soco super realista e interativo.

Além disso, vou explicar a diferença entre Heartbeat e Touched, para que você entenda melhor como detectar colisões e melhorar a jogabilidade do seu jogo. Então, prepare-se para turbinar suas habilidades de programação e deixar seu jogo ainda mais incrível! 🚀

Confira o vídeo completo e aprenda como fazer! 🎮👇

Assista o Video Como Criar Soco 2.0 no Roblox Studio

Scripts Local Script

				
					
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Player = game.Players.LocalPlayer
local UserInputService = game:GetService("UserInputService")
local PunchEvent = ReplicatedStorage.PunchEvent



print("a")






local function onKeypress(input, gameProcessed)
	if input.KeyCode==Enum.KeyCode.F and not gameProcessed then
		print("a")
		PunchEvent:FireServer()
		
	end
end

UserInputService.InputBegan:Connect(onKeypress)
				
			

Scripts Server Script

				
					local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local TweenService = game:GetService("TweenService")
local PunchEvent = ReplicatedStorage.PunchEvent
--local PunchEvent = Instance.new("RemoteEvent", ReplicatedStorage)
--PunchEvent.Name = "PunchEvent"
local debounce ={}
local sound= Instance.new("Sound")
sound.Parent = workspace
sound.SoundId="rbxassetid://8595980577"


local animation = Instance.new("Animation")
animation.AnimationId="rbxassetid://73224367529564"

PunchEvent.OnServerEvent:Connect(function(player)
	local character = player.Character
	if not character then return end
	
	

	local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")
	if not humanoidRootPart then return end
	
	local humanoid = character:FindFirstChildOfClass("Humanoid")
	if not humanoid then return end
	
	local animator = humanoid:FindFirstChildOfClass("Animator")
	local animatorTrack = animator:LoadAnimation(animation)
	animatorTrack:Play()
	-- Acessar a mão do jogador (LeftHand)
	local leftHand = character:FindFirstChild("LeftHand")
	if not leftHand then return end
	local tamanho = leftHand.Size
	-- Criar o tween para aumentar o tamanho da mão
	local tweenInfo = TweenInfo.new(0.3, Enum.EasingStyle.Bounce, Enum.EasingDirection.Out)
	local goal = {Size = leftHand.Size * 5} -- Aumentar 1.5 vezes o tamanho original
	local tween = TweenService:Create(leftHand, tweenInfo, goal)
	sound:Play()
	-- Iniciar o tween para aumentar a mão
	tween:Play()

	-- Após 0.1 segundos, diminuir de volta o tamanho
	tween.Completed:Connect(function()
		-- Criar o tween para restaurar o tamanho da mão
		local goalRestore = {Size = tamanho} -- Restaurar ao tamanho original
		local tweenRestore = TweenService:Create(leftHand, tweenInfo, goalRestore)
		tweenRestore:Play()
	end)

	-- Configurar hitbox
	local hitbox = Instance.new("Part")
	hitbox.Size = Vector3.new(4, 4, 4)
	hitbox.CFrame = humanoidRootPart.CFrame * CFrame.new(0, 0, -3)
	hitbox.Transparency = 1
	hitbox.CanCollide = false
	hitbox.Anchored = false
	hitbox.Parent = workspace

	-- Mover hitbox rapidamente
	local velocity = Instance.new("BodyVelocity")
	velocity.Velocity = humanoidRootPart.CFrame.LookVector * 50
	velocity.MaxForce = Vector3.new(4000, 4000, 4000)
	velocity.Parent = hitbox

	-- Parâmetros de detecção
	local overlapParams = OverlapParams.new()
	overlapParams.FilterDescendantsInstances = {character}
	overlapParams.FilterType = Enum.RaycastFilterType.Blacklist

	local hitTargets = {}

	-- Verificação de colisão
	RunService.Heartbeat:Connect(function()
		local parts = workspace:GetPartBoundsInBox(hitbox.CFrame, hitbox.Size, overlapParams)

		for _, part in ipairs(parts) do
			if hitTargets[part] then continue end
			hitTargets[part] = true

			-- Aplicar força em QUALQUER objeto
			local root = part:IsA("BasePart") and part or part.Parent:FindFirstChild("HumanoidRootPart") or part.Parent.PrimaryPart

			if root and root:IsA("BasePart") then
				-- Força do soco
				local knockbackDirection = (root.Position - humanoidRootPart.Position).Unit
				local knockbackForce = knockbackDirection * 100 + Vector3.new(0, 50, 0)

				-- Remover física existente
				for _, v in ipairs(root:GetChildren()) do
					if v:IsA("BodyVelocity") or v:IsA("BodyPosition") then
						v:Destroy()
					end
				end

				-- Aplicar nova física
				root.Anchored = false
				local bodyVelocity = Instance.new("BodyVelocity")
				bodyVelocity.Velocity = knockbackForce
				bodyVelocity.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
				bodyVelocity.Parent = root

				-- Remover após 0.5s
				game:GetService("Debris"):AddItem(bodyVelocity, 0.5)

				-- Aplicar dano se for Humanoid
				local humanoid = part.Parent:FindFirstChild("Humanoid") or part.Parent.Parent:FindFirstChild("Humanoid")
				if humanoid and not debounce[player.UserId] then
					debounce[player.UserId]= true
					humanoid:TakeDamage(20)
					
				end
			end
		end
		wait(1)
		debounce[player.UserId] = nil
	end)

	-- Limpar hitbox
	game:GetService("Debris"):AddItem(hitbox, 0.5)
end)

				
			

Conheça os Cursos de Programação para Crianças e Adolescentes

Se você quer aprender mais sobre programação de jogos e desenvolver suas próprias criações no Roblox Studio, confira nossos cursos na Programação For Kids! 🎮 Nosso curso foi criado especialmente para crianças e adolescentes que querem dar os primeiros passos no mundo da programação de forma divertida e interativa.

Leave a Reply

O seu endereço de e-mail não será publicado. Campos obrigatórios são marcados com *