|
| 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 |
|
|
| |
|
| |
|
| |
|
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
|
  |
| 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 |
|
|
|
| 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 |
|
|
| |
|