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 » Scripters
Home Search
 

Re: Gui/Part Script Problem

Previous Thread :: Next Thread 
agentghost6 is not online. agentghost6
Joined: 08 Dec 2012
Total Posts: 28
12 Nov 2016 07:19 PM
I'm trying to make a game and I have a button on a gui to activate placing a brick. The problem is that when I double click the button I can place bricks infinitely. I want it to let me click, place the brick, then repeat. It does that if I click the button once, but hitting more than once makes it infinite. Here's the script. Also, it would be awesome if you could optimize it if you can!

Player = game.Players.LocalPlayer
serverstoragevar = game:GetService("ServerStorage")
placing = nil
frame = game:GetService("StarterGui").ScreenGui.Frame



function placeunit()
local Mouse = Player:GetMouse()
mousedown = Mouse.Button1Down:connect(function()
if Mouse.Target ~= nil then
if placing ~= true then
placing = true
local unitSelected = serverstoragevar.InfUnits["Heavy Infantry"]
local createdUnit = unitSelected:Clone()
createdUnit.Parent = game.Workspace
createdUnit:SetPrimaryPartCFrame(Mouse.Hit)
placing = false
mousedown:disconnect()
end
end
end)
end



script.Parent.MouseButton1Click:connect(placeunit)
Report Abuse
VilgO is not online. VilgO
Joined: 15 Feb 2011
Total Posts: 518
12 Nov 2016 07:38 PM
Not sure what exactly goes wrong and what do you expect. Does it spawn more than one brick at once? Do you want to create one brick per click? Do you want to turn off the button after the first click?

Why do you connect to Mouse.Button1Down? It would fire immediately since the user just clicked the button, wouldn't it? Do you want the user to press the button and then click elsewhere to create a brick there? If you do, you could use PlayerMouse.Changed instead.
Report Abuse
agentghost6 is not online. agentghost6
Joined: 08 Dec 2012
Total Posts: 28
12 Nov 2016 07:45 PM
When I click the button, I want to be able to place one brick then have to click the button again. I do want the user to click the button to click elsewhere to place the brick.
Report Abuse
agentghost6 is not online. agentghost6
Joined: 08 Dec 2012
Total Posts: 28
12 Nov 2016 07:48 PM
Can you make an example script with the PlayerMouse.Changed?
Report Abuse
VilgO is not online. VilgO
Joined: 15 Feb 2011
Total Posts: 518
12 Nov 2016 08:05 PM
Nevermind, PlayerMouse.Changed fires when a property changes, and Mouse doesn't have a property like Button1IsDown or something.

You need another variable. It should be set to true when the user presses the button and set to false when they create a brick.
Maybe you won't need to change anything else, though I'm not sure why doesn't mouse.Button1Down fire immediately after the button is pressed.
Report Abuse
agentghost6 is not online. agentghost6
Joined: 08 Dec 2012
Total Posts: 28
12 Nov 2016 08:07 PM
I think it doesn't fire immediately after because it's called after you press the button, so there is a small delay between the button and the event. Thanks for the help!
Report Abuse
agentghost6 is not online. agentghost6
Joined: 08 Dec 2012
Total Posts: 28
12 Nov 2016 08:14 PM
It works now! Thank you.
Report Abuse
VilgO is not online. VilgO
Joined: 15 Feb 2011
Total Posts: 518
12 Nov 2016 08:19 PM
You're welcome :)
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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