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: Issue prevails everytime i make this script

Previous Thread :: Next Thread 
ilikepiehaha is not online. ilikepiehaha
Joined: 02 Aug 2011
Total Posts: 316
07 Sep 2013 05:07 PM
I rewrite this code constantly because it's useful in my RTS games. But this time I messed up and can't, for the love of God, remember how to fix this. The problem is that, yes, it will stop activating when I click when it's deselected, but for every time I deselect it, it does the code for that many times when I click. For instance, if I were to select it twice, by selecting, deselecting, and then selecting again, it would do the Button1Down twice, and so forth. How do I fix this?

local bin = script.Parent
local plr = bin.Parent.Parent
local char = plr.Character
local mouse = plr:GetMouse()
local enabled = false

bin.Selected:connect(function()

enabled = true

lC = Instance.new("Part")
lC.Parent = char
lC.Material = "Plastic"
lC.Reflectance = 0
lC.Transparency = .4
lC.Name = "lootC"
lC.Anchored = true
lC.CanCollide = false
lC.Locked = true
lC.FormFactor = Enum.FormFactor.Plate
lC.Size = Vector3.new(1, .4, 1)
lC.TopSurface = Enum.SurfaceType.Smooth
lC.BottomSurface = Enum.SurfaceType.Smooth

mouse.Move:connect(function()

mag = (char.Torso.Position - mouse.Hit.p).magnitude

lC.CFrame = CFrame.new(mouse.Hit.p)

if (mag <= 10) then
lC.BrickColor = BrickColor.new("Lime green")
elseif (mag > 10) then
lC.BrickColor = BrickColor.new("Really red")
end
end)

mouse.Button1Down:connect(function()

if enabled then
if (mag <= 10) then
print("Checking...")
-- add stuff later
elseif (mag > 10) then
print("Too far away.")
end
end
end)

bin.Deselected:connect(function()
wait(.1)
enabled = false
if lC then
lC:Destroy()
end
end)
end)
Report Abuse
ilikepiehaha is not online. ilikepiehaha
Joined: 02 Aug 2011
Total Posts: 316
07 Sep 2013 05:13 PM
Bumpcanoe
Report Abuse
ilikepiehaha is not online. ilikepiehaha
Joined: 02 Aug 2011
Total Posts: 316
07 Sep 2013 05:25 PM
Bumpitty bump
Report Abuse
ilikepiehaha is not online. ilikepiehaha
Joined: 02 Aug 2011
Total Posts: 316
08 Sep 2013 10:03 AM
Am I alone here...
Report Abuse
Bebee2 is not online. Bebee2
Joined: 17 May 2009
Total Posts: 3985
08 Sep 2013 10:11 AM
Place the button1down within the 'bin.Selected:connect(function()'
Report Abuse
Bebee2 is not online. Bebee2
Joined: 17 May 2009
Total Posts: 3985
08 Sep 2013 10:12 AM
Meh, it may not work like that. I suddenly forgot how to fix it.
Report Abuse
ilikepiehaha is not online. ilikepiehaha
Joined: 02 Aug 2011
Total Posts: 316
08 Sep 2013 10:26 AM
It's already in it. It's just not the first thing there. lC is a brick that follows the mouse, and it turns red when more than 10 studs away, green when less than 10 studs. If you click when within the green range, it says Checking, but says too far away when in red. The problem is that it does it as many times as is equivalent to however many times I've deselected it, so that output says "Checking checking checking" if I've deselected 3 times, etc. This bothers me because that tool will be used for looting, and if it occurs more than once, the player will receive more than he/she needs.
Report Abuse
ilikepiehaha is not online. ilikepiehaha
Joined: 02 Aug 2011
Total Posts: 316
08 Sep 2013 01:53 PM
Bawmp
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