Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

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

Asked by 2 days ago
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!

0
By the way :KeyDown is deprecated use UserInputService JesseSong 3389 — 2d

1 answer

Log in to vote
0
Answered by 1 day ago
Edited 1 day ago
-- 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
Ad

Answer this question