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
 

Help

Previous Thread :: Next Thread 
captainfryx is not online. captainfryx
Joined: 11 Jun 2013
Total Posts: 19
15 Jun 2013 05:12 PM
I am new to scripting, and right now im trying to make a button that you have to pay gold in order to regenerate somthing. My first part I made worked(This part checked to see if you have the right amount of gold) How would I make it so that script is combined with the regen script below? I have tried a couple of things but it did not work.

CHECKER

function onTouch(Brick)
local Character=Brick.Parent
local Player = game.Players[Character.Name]
local Gold=Player.leaderstats:findFirstChild("Gold")
if (Player~=nil) then
if Gold.Value >= 1 then
print'works'
end
end
end
script.Parent.Touched:connect(onTouch)


REGEN

model = script.Parent.Parent--Indicates that the script interacts with the model the button is grouped with.
messageText = ""--If you want a message to appear upon pressing, type it here.

message = Instance.new("Message")
message.Text = messageText
backup = model:clone()
enabled = true

function onTouch(Brick)
local Character=Brick.Parent
local Player = game.Players[Character.Name]
local Gold=Player.leaderstats:findFirstChild("Gold")
if (Player~=nil) then
if Gold.Value >= 1 then
message.Parent = game.Workspace
model:remove()

wait(0.1)--Change this number to display the regen message as long as you want in seconds.

model = backup:clone()
model.Parent = game.Workspace
model:makeJoints()
message.Parent = nil

script.Disabled = true
script.Parent.BrickColor = BrickColor.new(26)--Black
wait(5)--Change this number to change the time in between regenerations via the button, in seconds..
script.Parent.BrickColor = BrickColor.new(104)--Purple
script.Disabled = false
end
end
end


function onHit(hit)
if (hit.Parent:FindFirstChild("Humanoid") ~= nil) and enabled then
onTouch()
end
end

script.Parent.Touched:connect(onHit)


Report Abuse
BurnFireWindWX is not online. BurnFireWindWX
Joined: 08 May 2011
Total Posts: 5903
15 Jun 2013 05:14 PM
[ Content Deleted ]
Report Abuse
zakary99 is not online. zakary99
Joined: 19 Jan 2010
Total Posts: 1095
15 Jun 2013 05:22 PM
You didn't make that.
Report Abuse
captainfryx is not online. captainfryx
Joined: 11 Jun 2013
Total Posts: 19
15 Jun 2013 05:53 PM
I did not make the regen, but I need this so I can complete the structure of my game. Without the basic structure the whole thing falls.
Report Abuse
ArbiterOfDeath is not online. ArbiterOfDeath
Joined: 20 Jun 2011
Total Posts: 1458
15 Jun 2013 06:09 PM
I can see how you worked on that script. You must know that I'm vary impressed by how you were able to piece it together. I wish must starters were like you.

Anyways, I saw the problem. While you did stick the if statement into the function correctly, you also added "Brick" into the list of function arguments. Normally with the Touch event, that would be fine, however it is not the function that gets called when the button is touched, and therefor doesn't get the brick that touched it. The function OnHit is called first when the button is touched and is given the brick that touched it. OnHit then calls The main regeneration function, whose name escapes me, that you added the if statements into.

So from this point, there is two things you could do. One is easier, and one is more elegant. I'm not going to do them sense you are learning, but tell you how to do it.

I'll start with the easier option. You can look at the function OnHit, and see were it calls the main regeneration function. You'll then see that the braces are empty, and you need to put the variable that contains the part that touched the button in there.

The more elegant option is to instead put your if statements into the OnHit function, and only call the main regeneration function if the person has enough gold. You were able to do that to the other function already, so you should be able to do this if you want too.
Report Abuse
captainfryx is not online. captainfryx
Joined: 11 Jun 2013
Total Posts: 19
15 Jun 2013 06:13 PM
I did not make the regeneration script. It is hard to understand what you just said but I will try.
Report Abuse
captainfryx is not online. captainfryx
Joined: 11 Jun 2013
Total Posts: 19
15 Jun 2013 06:16 PM
Braces?
Report Abuse
captainfryx is not online. captainfryx
Joined: 11 Jun 2013
Total Posts: 19
15 Jun 2013 07:16 PM
I do not get it.
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