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 » Scripting Helpers
Home Search
 

Re: I Need Help With This

Previous Thread :: Next Thread 
xPoloBear is not online. xPoloBear
Joined: 10 Oct 2011
Total Posts: 202
10 Nov 2013 03:31 PM
I scripted this, so when you shoot a player, his humanoid.Health takes 10 out.

My Script:


player = game.Players.LocalPlayer
mouse = player:GetMouse()

enabled = true
function onButton1Down(mouse)
if not enabled then return end
enabled = false
mouse.Icon = "rbxasset://textures\\GunWaitCursor.png"
local h = mouse.Target[mouse.Name].Parent:findFirstChild("Humanoid")
if (mouse.Target ~= nil) and (h ~= nil) then
h.Health = h.Health - 25
end
wait(.2)
mouse.Icon = "rbxasset://textures\\GunCursor.png"
enabled = true

end

function onEquipped(mouse)
x = script.Parent.Handle.Equip
x:Play()
mouse.Icon = "rbxasset://textures\\GunCursor.png"
mouse.Button1Down:connect(function() onButton1Down(mouse) end)
end


script.Parent.Equipped:connect(onEquipped)

Output Error:

16:30:03.257 - Instance is not a valid member of Part
16:30:03.259 - Script 'Players.xPoloBear.Backpack.Flintlock.Local Gui', Line 9 - global onButton1Down
16:30:03.265 - Script 'Players.xPoloBear.Backpack.Flintlock.Local Gui', Line 23
16:30:03.266 - stack end
Report Abuse
notsopwnedg is not online. notsopwnedg
Joined: 07 Nov 2010
Total Posts: 4182
10 Nov 2013 03:44 PM
You can't set the mouse Icon using GetMouse I don't think...
Report Abuse
wazap is not online. wazap
Joined: 29 Jun 2007
Total Posts: 23234
10 Nov 2013 03:45 PM
local h = mouse.Target[mouse.Name].Parent:findFirstChild("Humanoid")

This should be
local h = mouse.Target.Parent:findFirstChild("Humanoid")

I also recommend putting, before this line,
if not mouse.Target then wait(.1) enabled = true return end
Report Abuse
xPoloBear is not online. xPoloBear
Joined: 10 Oct 2011
Total Posts: 202
10 Nov 2013 03:55 PM
It works But now when i shoot in to sky, i get this

16:54:51.399 - Players.xPoloBear.Backpack.Flintlock.Local Gui:11: attempt to index field 'Target' (a nil value)
16:54:51.400 - Script 'Players.xPoloBear.Backpack.Flintlock.Local Gui', Line 11 - global onButton1Down
16:54:51.403 - Script 'Players.xPoloBear.Backpack.Flintlock.Local Gui', Line 30
16:54:51.406 - stack end
Report Abuse
wazap is not online. wazap
Joined: 29 Jun 2007
Total Posts: 23234
10 Nov 2013 03:57 PM
Can i see the new script?
Report Abuse
xPoloBear is not online. xPoloBear
Joined: 10 Oct 2011
Total Posts: 202
10 Nov 2013 04:00 PM
player = game.Players.LocalPlayer
mouse = player:GetMouse()
f = script.Parent.Handle.Shot

enabled = true
function onButton1Down(mouse)
if not enabled then return end
enabled = false
mouse.Icon = "rbxasset://textures\\GunWaitCursor.png"
f:Play()
local h = mouse.Target.Parent:findFirstChild("Humanoid")
if (mouse.Target ~= nil) and (h ~= nil) then
h.Health = h.Health - 25
else if (mouse.Target ~= nil) and not (h ~= nil) then
print("Not Found")
end
end
wait(5)
mouse.Icon = "rbxasset://textures\\GunCursor.png"
enabled = true

end

function onEquipped(mouse)
x = script.Parent.Handle.Equip
x:Play()
mouse.Icon = "rbxasset://textures\\GunCursor.png"
mouse.Button1Down:connect(function() onButton1Down(mouse) end)
end


script.Parent.Equipped:connect(onEquipped)
Report Abuse
xPoloBear is not online. xPoloBear
Joined: 10 Oct 2011
Total Posts: 202
10 Nov 2013 04:12 PM
Anyone?
Report Abuse
wazap is not online. wazap
Joined: 29 Jun 2007
Total Posts: 23234
10 Nov 2013 09:29 PM
My earlier post

"local h = mouse.Target[mouse.Name].Parent:findFirstChild("Humanoid")

This should be
local h = mouse.Target.Parent:findFirstChild("Humanoid")

I also recommend putting, before this line,
if not mouse.Target then wait(.1) enabled = true return end"

Clearly you did not do the last line that I recommended
This would've prevented that.

So put
if not mouse.Target then wait(.1) enabled = true return end
Before local h = mouse.Target.Parent:findFirstChild("Humanoid")
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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