Well, first off.. Let me show you how this is set up...
Each person has a HopperBin tool for each upgrade.. within that tool is the script that you will see below and IntValue (type)
Each type has the value of the upgrade.. What the script doesn't understand is the value for the upgrade so it will try to upgrade every IntValue that's located within another of 'stats' (stats is what holds all of the upgrades)
Here is the script...
print("Loaded the script")
local bin = script.Parent
local player = game.Players.LocalPlayer
local Mouse = player:GetMouse()
function round(num, idp)
local mult = 10^(idp or 0)
return math.floor(num * mult + 0.5) / mult
end
print("Info1")
function onButton1Down()
if player == nil then
return
end
print("Info2")
points = player.leaderstats["Stat Points"]
type = bin.Type.Value
upg = player.stats[type]
cost = math.floor(upg.Value ^ 1.35 / 10) + 1
if(points.Value < cost) then return end
if(upg.Value >= 4999) then return end
upg.Value = upg.Value + 1
print("Info3")
player.leaderstats["Level"].Value = player.leaderstats["Level"].Value + 1
points.Value = points.Value - cost
bin.Name = type .. ": " .. upg.Value
end
bin.Selected:connect(function()
Mouse.Button1Down:connect(onButton1Down)
end)
Where it messes up is at line 24.
upg.Value = upg.Value + 1
Should I just change it to...
player.stats.(upgradestat) = player.stats.(upgradestat) + 1
Would that be the easiest way to fix it or is there another way that would make it look nicer and work better?
Edit: I just tried what I said above, and it didn't work. So I might need to redo the entire setup? It used to work fine in solo mode but not in a server before it got changed. Here is the link to the question before this.. https://scriptinghelpers.org/questions/3886/fuction-onbutton1down-not-working-correctly
More Edit: This is the current script I am using to test. If a person says 'Try this 'Input Suggestion Here' ' I will do it and post the script that I tried below. I will simply edit it to the current/last suggestion so everyone knows where I stand.
print("Loaded the script")
local bin = script.Parent
local player = game.Players.LocalPlayer
local Mouse = player:GetMouse()
function round(num, idp)
local mult = 10^(idp or 0)
return math.floor(num * mult + 0.5) / mult
end
print("Info1")
function onButton1Down()
if player == nil then
return
end
print("Info2")
points = player.leaderstats["Stat Points"]
ups = bin.Upgrade.Value
upg = player.stats[ups]
cost = math.floor(upg.Value ^ 1.35 / 10) + 1
if(points.Value < cost) then return end
if(upg.Value >= 4999) then return end
upg.Value = upg.Value + 1
print("Info3")
player.leaderstats["Level"].Value = player.leaderstats["Level"].Value + 1
points.Value = points.Value - cost
bin.Name = ups .. ": " .. upg.Value
end
bin.Selected:connect(function()
Mouse.Button1Down:connect(onButton1Down)
end)

2 comments
What is the output error?
Nothing. It does what it should, but also more. And I want it to change it so it doesn't do the more. It works perfectly fine otherwise.