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

how to left click to punch?

can anyone can help me about keybutton cause i don't it's gonna be key "f" Sorry For my grammar

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local dmg = true

Mouse.KeyDown:connect(function(key)
 if key == "f" then 
  local an = script.Parent.Humanoid:LoadAnimation(script.Animation)
  an:Play()
  script.Parent.RightHand.Touched:connect(function(hit)
   if hit.Parent.Humanoid and dmg == true then
    hit.Parent.Humanoid:TakeDamage(10) 
    dmg = false
    wait(1)
    dmg = true
   end
  end)
 end
end)

3 comments

0

So you want it to punch when left click and not when the "f" button is pressed am i correct?

0

Yes

0

why are you trying to damage the player on the client, sigh use remote events + userinputservice if your trying to make actions with player input

1 answer

✓ Accepted answer

Well i can't really test it cause i don't have time and i'm tired, going to sleep but here test this out

Fixed script

(localscript)

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local dmg = true

Mouse.Button2Down:Connect(function()
  local an = script.Parent.Humanoid:LoadAnimation(script.Animation)
  an:Play()
  script.Parent.RightHand.Touched:connect(function(hit)
   if hit.Parent.Humanoid and dmg == true then
    game.ReplicatedStorage.punch:FireServer(hit.Parent.Name,10)
    dmg = false
    wait(1)
    dmg = true
   end
  end)
end)

(serverscript)

game.ReplicatedStorage.punch.OnServerEvent:Connect(function(sender,who,damage)
	workspace[who]"Humanoid":TakeDamage(damage)
end)

9 comments

0

okay i'll try

0

If there's any errors just tell me the error it said and i'll fix it don't worry.

0

theres one big error, your trying to damage the player on the client, im gonna let you figure out why thats bad

0

I just added the left click part honestly, and i know why it's bad lol.

0

I know it's client sided i'm not dumb

0

then why do you have the "takedamage" function inside of a "button2down" event, you could have separated the code blocks of what script that code is in

0

Like i said i just fixed the fact that it was right click not left.

0

but there you go fixed it so it's FE just for you.

0

Thanks it's work

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