|
| 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 |
|
|
| |
|
zakary99
|
  |
| Joined: 19 Jan 2010 |
| Total Posts: 1095 |
|
| |
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
| |
|
| |
|