I used a YouTube tutorial to help me make a punch script. Everything worked perfectly except for the fact that the damage was client-sided. So just now I tried making it server-sided; it was kinda thrown together with the help of some research and extra tutorials, and it was a bit hard for me to imagine so I could put it together, so it may just be my own brain's fault. Here are the scripts:
Local Script Activates the animation, sends out the remote event, etc
CanDoDmg = true
Keybind = "q"
dmg = 10
local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
local ReplicatedStorage = game.ReplicatedStorage
local PunchHit = ReplicatedStorage.RemoteEvents.PunchHit
local Damage = game.Workspace.Damage
local PlayerHit = game.Workspace.PlayerHit
mouse.KeyDown:Connect(function(key)
if key == Keybind then
local anim = script.Parent.Humanoid:LoadAnimation(script.Animation)
anim:Play()
script.Parent.RightHand.Touched:connect(function(hit)
if hit.Parent.Humanoid and CanDoDmg == true then
PlayerHit = hit.Parent
Damage = dmg
PunchHit:FireServer()
-- hit.Parent.Humanoid:TakeDamage(dmg)
CanDoDmg = false
wait(1)
CanDoDmg = true
end
end)
end
end)
Server Script Receives the remote event and executes the damage
local ReplicatedStorage = game.ReplicatedStorage
local PunchHit = ReplicatedStorage.RemoteEvents.PunchHit
local Players = game.Players
local Damage = game.Workspace.Damage
local PlayerHit = game.Workspace.PlayerHit
local Plr = ""
PunchHit.OnServerEvent:Connect(function()
Plr = PlayerHit
Players.Plr.Humanoid:TakeDamage(Damage)
end)
