Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- This code goes in a LocalScript inside StarterPlayerScripts
- --// Services
- local UserInputService = game:GetService('UserInputService')
- local ReplicatedStorage = game:GetService('ReplicatedStorage')
- local Players = game:GetService('Players')
- --// Debounces
- local Punching = false
- local Damaging = true
- --// Customisation
- local Damage = inf
- local Cooldown = 0.2
- --// Events
- local PunchEvent = ReplicatedStorage:WaitForChild('PunchEvent')
- --// Player
- local Player = game.Players.LocalPlayer
- local Character = game.Workspace:WaitForChild(Player.Name)
- local Humanoid = Character:FindFirstChildOfClass('Humanoid')
- local RightArm = Character:WaitForChild('Right Arm')
- --//Animations
- Punch = Instance.new('Animation')
- Punch.AnimationId = 'rbxassetid://953446258'
- PunchTrack = Humanoid:LoadAnimation(Punch)
- --// Coding
- UserInputService.InputBegan:Connect(function(Input)
- if Input.KeyCode == Enum.KeyCode.E and not Punching then
- Punching = true
- PunchTrack:Play()
- PunchTrack.KeyframeReached:Connect(function(Keyframe)
- if Keyframe == 'End' then
- wait(Cooldown)
- Punching = false
- Damaging = true
- end
- end)
- end
- end)
- RightArm.Touched:Connect(function(hitPart)
- if Punching and hitPart.Parent:FindFirstChild('Humanoid') and Damaging then
- Damaging = false
- local HumanoidToDamage = hitPart.Parent:FindFirstChild('Humanoid')
- PunchEvent:FireServer(HumanoidToDamage, Damage)
- end
- end)
- This code goes inside a Script inside ServerScriptService
- --// Services
- local ReplicatedStorage = game:GetService('ReplicatedStorage')
- --// Events
- local PunchEvent = ReplicatedStorage:WaitForChild('PunchEvent')
- --// Coding
- PunchEvent.OnServerEvent:Connect(function(PlayerWhoSent, HumanoidToDamage, Damage)
- HumanoidToDamage:TakeDamage(Damage)
- end)
- Make sure you create a RemoteEvent called 'PunchEvent' and parent it to the ReplicatedStorage
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement