Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Is there any way to make this more clear for the script?

Asked by
lomo0987 250 Moderation Voter
10 years ago

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)

0
What is the output error? ChipioIndustries 454 — 10y
0
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. lomo0987 250 — 10y

1 answer

Log in to vote
0
Answered by
Dummiez 360 Moderation Voter
10 years ago

EDIT: Thread solved.

0
So you are saying to just rename to something else and edit the script to work around it as it's taking 'Type' not as a name but something else? lomo0987 250 — 10y
0
Btw, I tried that and it still didn't work. lomo0987 250 — 10y
0
Actually in line 19, change bin.Type.Value to bin.Type Dummiez 360 — 10y
0
Where is the output error at? Dummiez 360 — 10y
View all comments (10 more)
0
I found the error, line 28 set the ups to ups.Value Dummiez 360 — 10y
0
I found a different error.. line 20: bad argument # 2 to '?' (string expected, got userdata) Then it goes on to say that it has got a stack end... Here is a pic of it http://gyazo.com/804b7b978bc5153de6662ab0656df220 lomo0987 250 — 10y
0
can you update the code? Dummiez 360 — 10y
0
I used what you have. lomo0987 250 — 10y
0
OHHHH, I see, if you check on line 20.. It says "upg = player.stats[ups]" but ups doesn't have a value. So it's trying to get is bin.Upgrade Not bin.Upgrade.Value And the value is the name of the upgrade.. I also fixed that and tested.. the same problem is still happening.. XD lomo0987 250 — 10y
0
can you send me the model? see if you can save it as .rbxm Dummiez 360 — 10y
0
I found the bug.. What happens is that each time i select the tool... it 'saves' that i had it out, and each time I click, it tries to do the onButton1Down function. Is there any way to edit that to make it check to see if the tool is out then return end? lomo0987 250 — 10y
0
Try using the deselected event to reset the script Dummiez 360 — 10y
0
I'm needed a bit of help with that, Is there a wiki page you could bring me to or help me with the function? I can get the function, just don't know how to end the script with it. I tried return, but it didn't do anything unless I did it wrong. lomo0987 250 — 10y
0
Btw, I fixed it. I went to the first script that broke, and I changed function to onclick, because it never understood what button1mouse was. lomo0987 250 — 10y
Ad

Answer this question