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

Fuction onButton1Down Not working correctly?

Asked by
lomo0987 250 Moderation Voter
10 years ago

I have put a few prints inside the script to see what wasn't working, info 2 and info 3 doesn't come up. Is there anything wrong with the function onButton1Down(mouse)?

print("Loaded the script")
local bin = script.Parent

function round(num, idp)
    local mult = 10^(idp or 0)
    return math.floor(num * mult + 0.5) / mult
end
print("Info1")


function onButton1Down(mouse)
    local player = game.Players.LocalPlayer
    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

function onSelected(mouse)
    print("select")
    mouse.Button1Down:connect(function() onButton1Down(mouse) end)
end

bin.Selected:connect(onSelected)

1 answer

Log in to vote
0
Answered by 10 years ago

You never stated the PlayerMouse, and also the connection line was just a little weird

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)
0
Sweet. It works now! :D lomo0987 250 — 10y
0
There are some bugs with the script... lomo0987 250 — 10y
Ad

Answer this question