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
 

button does nothing when clicked

Previous Thread :: Next Thread 
johny220 is not online. johny220
Joined: 30 Oct 2011
Total Posts: 4584
13 Aug 2015 02:40 PM
cost = script.Parent
level = script.Parent.Parent.Level
button = script.Parent.Parent.Parent
ChaChing = game.Players.LocalPlayer.leaderstats.Cash
mpc = game.Players.LocalPlayer.Backpack.MPC

if level.Value == 1 then cost.Value = 50 mpc.Value = 1
elseif level.Value == 2 then cost.Value = 125 mpc.Value = 3
elseif level.Value == 3 then cost.Value = 300 mpc.Value = 5
elseif level.Value == 4 then cost.Value = 800 mpc.Value = 10
elseif level.Value == 5 then cost.Value = 2000 mpc.Value = 25
elseif level.Value == 6 then cost.Value = 3200 mpc.Value = 35
elseif level.Value == 7 then cost.Value = 5000 mpc.Value = 50
elseif level.Value == 8 then cost.Value = 11500 mpc.Value = 100
elseif level.Value == 9 then cost.Value = 25000 mpc.Value = 150
elseif level.Value == 10 then cost.Value = 50000 mpc.Value = 200
elseif level.Value == 11 then cost.Value = 100000 mpc.Value = 500
elseif level.Value == 12 then cost.Value = 250000 mpc.Value = 1000
elseif level.Value == 13 then mpc.Value = 5000 script.Parent.Parent.Text = "MAX" script.Parent.Parent.TextColor3 = Color3.new(255, 39, 39) script.Parent.Parent.TextStrokeColor3 = Color3.new(170, 10, 10)
end

if ChaChing.Value >= cost.Value then
script.Parent.Parent.MouseButton1Down:connect(function()
script.Parent.Sound:Play()
level.Value = level.Value + 1
end)
end

--------------------------------------------------------

I checked the parents and all that. But nothing works and I have no idea why
Report Abuse
zarman3402 is not online. zarman3402
Joined: 18 May 2013
Total Posts: 1449
13 Aug 2015 02:41 PM
Is this a brick or gui?
Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
13 Aug 2015 02:48 PM
First of all we will clean up your code

local player = game.Players.LocalPlayer
local mpc = player.Backpack:WaitForChild("MPC")
local stats = player:WaitForChild("leaderstats")
local cash = stats:WaitForChild("Cash")
local cost = script.Parent
local label = cost.Parent
local level = label.Level
local button = label.Parent


if level.Value == 1 then
cost.Value = 50
mpc.Value = 1
elseif level.Value == 2 then
cost.Value = 125
mpc.Value = 3
elseif level.Value == 3 then
cost.Value = 300
mpc.Value = 5
elseif level.Value == 4 then
cost.Value = 800
mpc.Value = 10
elseif level.Value == 5 then
cost.Value = 2000
mpc.Value = 25
elseif level.Value == 6 then
cost.Value = 3200
mpc.Value = 35
elseif level.Value == 7 then
cost.Value = 5000
mpc.Value = 50
elseif level.Value == 8 then
cost.Value = 11500
mpc.Value = 100
elseif level.Value == 9 then
cost.Value = 25000
mpc.Value = 150
elseif level.Value == 10 then
cost.Value = 50000
mpc.Value = 200
elseif level.Value == 11 then
cost.Value = 100000
mpc.Value = 500
elseif level.Value == 12 then
cost.Value = 250000
mpc.Value = 1000
elseif level.Value == 13 then
mpc.Value = 5000
label.Text = "MAX"
label.TextColor3 = Color3.new(255, 39, 39)
label.TextStrokeColor3 = Color3.new(170, 10, 10)
end

if cash.Value >= cost.Value then
label.MouseButton1Down:connect(function()
cost.Sound:Play()
level.Value = level.Value + 1
end)
end

Never, after finally being able to read your horribly inefficient code,

you never added a .Changed function to level and cash.



"Talk is cheap. Show me the code." - Linus Torvalds
Report Abuse
johny220 is not online. johny220
Joined: 30 Oct 2011
Total Posts: 4584
13 Aug 2015 03:23 PM
^ you didn't really do a good job of cleaning it either you could've made a table

this is a part btw
Report Abuse
zarman3402 is not online. zarman3402
Joined: 18 May 2013
Total Posts: 1449
13 Aug 2015 03:31 PM
Ok I can fix this. Just change your connect to this:
Script.Parent.Parent.ClickDetector.MouseClick:connect
--assuming the 2nd parent is the part
-- and u need to insert a click detector
Report Abuse
lupine is not online. lupine
Joined: 24 Jun 2008
Total Posts: 3561
13 Aug 2015 03:36 PM
I fixed your code and made it look prettier, but for whatever reason it's breaking the posting rules of Roblox. I published it as a model.

http://www.roblox.com/Fixed-item?id=283655336
Report Abuse
WoolHat is not online. WoolHat
Joined: 19 May 2013
Total Posts: 1873
13 Aug 2015 03:41 PM
MPCTable = {} --insert mpc values that correspond to 1-13
CostTable = {} --insert cost values that correspond to 1-13

for i,v in pairs(MPCTable) do
if level.Value == i then
mpc.Value = v
if level.Value == 13 then
label.Text = "MAX"
label.TextColor3 = Color3.new(255, 39, 39)
label.TextStrokeColor3 = Color3.new(170, 10, 10)
elseif level.Value < 13 then
cost.Value = CostTable[i]
end
end
end


Something like that? I don't know if this is more EFFICIENT, but it should theoretically work. Time, what you did just made the format different. That doesn't have anything to do with efficiency, only preference.
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