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

Can anyone help out with a punch script? (trying to make it server sided)

ifDmg = true
Keyting = "e"
amountdmg = 10

local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()

mouse.KeyDown:Connect(function(key)
	if key == Keyting then
		local anim = script.Parent.Humanoid:LoadAnimation(script.Animation)
		anim:Play()
		anim.Looped = false	
		script.Parent.RightHand.Touched:Connect(function(hit)
				if hit.Parent.Humanoid and ifDmg == true then
					hit.Parent.Humanoid:TakeDamage(amountdmg)
					ifDmg = false
					wait(1)
					ifDmg = true
			end
		end)
	end
end)

Above is my script used to make the punching work but I was trying to make

mouse.KeyDown:Connect(function(key)

as a server sided, instead of it being client sided

and...

I dont know really on how to do that since the script has a parameter...

If there is anyway to make the script into a remote event, please answer or comment because it will help out..

thanks!

1 comment

0

By the way :KeyDown is deprecated use UserInputService

1 answer

-- i used remotes more on it here
-- https://developer.roblox.com/en-us/api-reference/class/RemoteEvent

-- here is the client script

ifDmg = true
Keyting = "e"
amountdmg = 10

local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()

mouse.KeyDown:Connect(function(key)
	if key == Keyting then
		script.Parent.RightHand.Touched:Connect(function(hit)
			if hit.Parent.Humanoid and ifDmg == true then
				game.ReplicatedStorage.Punch:FireServer(hit,amountdmg)
				ifDmg = false
				wait(1)
				ifDmg = true
			end
		end)
	end
end)

-- and server script

game.ReplicatedStorage.Punch.OnServerEvent:Connect(function(plr,hitpart,dmg)
	hitpart.Parent.Humanoid:TakeDamage(dmg)
end)
-- this is my first post don't judge me

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