Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

how to left click to punch?

Asked by 5 years ago

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)
0
So you want it to punch when left click and not when the "f" button is pressed am i correct? VitroxVox 884 — 5y
0
Yes OrewaKamidaa 40 — 5y
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 LoganboyInCO 150 — 5y

1 answer

Log in to vote
1
Answered by
VitroxVox 884 Moderation Voter
5 years ago
Edited 5 years ago

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)
0
okay i'll try OrewaKamidaa 40 — 5y
0
If there's any errors just tell me the error it said and i'll fix it don't worry. VitroxVox 884 — 5y
0
theres one big error, your trying to damage the player on the client, im gonna let you figure out why thats bad LoganboyInCO 150 — 5y
0
I just added the left click part honestly, and i know why it's bad lol. VitroxVox 884 — 5y
View all comments (5 more)
0
I know it's client sided i'm not dumb VitroxVox 884 — 5y
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 LoganboyInCO 150 — 5y
0
Like i said i just fixed the fact that it was right click not left. VitroxVox 884 — 5y
0
but there you go fixed it so it's FE just for you. VitroxVox 884 — 5y
0
Thanks it's work OrewaKamidaa 40 — 5y
Ad

Answer this question