generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Game Design
Home Search
 

Re: Mouse

Previous Thread :: Next Thread 
DanPai is online. DanPai
Joined: 03 Jun 2016
Total Posts: 355
18 Jun 2017 02:15 PM
I just started scripting about two months ago, so I'm not really good at it. Anyway, I am trying to make it so that when a player clicks on another, the player that was clicked on takes damage.

I have this script but it's most likely completely wrong.

mousey = game.Players.LocalPlayer:GetMouse()
hum = mousey:FindFirstChild("Humanoid")

--

function Attack()
if mousey.Target == hum then
hum:TakeDamage(50)
end
end

--

mousey.Button1Down:connect(function(Attack)
end)
Report Abuse
Crxsh is not online. Crxsh
Joined: 11 Nov 2012
Total Posts: 7152
18 Jun 2017 02:17 PM
Wrong forum, go to 'Scripting' for help on this.


why u asken all dem questions?
Report Abuse
ParaText is not online. ParaText
Joined: 15 Aug 2016
Total Posts: 799
18 Jun 2017 02:26 PM
Mouse is doesn't have any yield functions so :FindFirstChild() is completely out of place

First, you have to get what the mouse is pointing to, the exact part/model, with Mouse.Target

Next, check if the the target is actually a player's character, and if so, make sure that the character has a humanoid in it:

if players:FindFirstChild(mouse.Target) then
if mouse.Target:FindFirstChild("Humanoid")
local hum = mouse.Target.Humanoid
hum.Health = hum.Health - DAMAGE_TAKEN

and then subtract the damage from the humanoid's health
also make sure you use a debounce so that people can't spam click

local debounce = false
if players:FindFirstChild(mouse.Target) and not debounce then
if mouse.Target:FindFirstChild("Humanoid")
debounce = true
local hum = mouse.Target.Humanoid
hum.Health = hum.Health - DAMAGE_TAKEN
wait(TIME_TO_WAIT)
debounce = false




Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Game Design
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image