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

My script doesn't seem to be working?

Asked by 10 years ago

This is supposed to add money to the money int value in the leaderstats when it touched the brick at the end of my tycoon thingy. It was working, but not anymore? Any ideas?

game.Players.PlayerAdded:connect(function(player)
    local leaderstats = Instance.new("Model",player)
    leaderstats.Name = "leaderstats"
    local money = Instance.new("IntValue", leaderstats)
    money.Name = "Money"
    money.Value = 0
function addMoney(b)
    if b.Name == "MONEYBRICK" then
        money.Value = money.Value + 5
        if game.Workspace.UPGRADE1.Touched and b.Name == "MONEYBRICK" then
        money.Value = money.Value + 5
        end
    end
end
function buyupgrade1()
    if money.Value >= 50 then
        money.Value = money.Value - 50
    c = game.Lighting.UPGRADE1:Clone()
    wait(.5)
    c.Parent = game.Workspace
    game.Workspace.pp:Destroy()
    c.Transparency = 0.7
    wait(1)
    c.Transparency = 0.5
    wait(1)
    c.Transparency = 0.3
    wait(1)
    c.Transparency = 0 
    end
end
end)
game.Workspace.pp.Touched:connect(buyupgrade1)
game.Workspace.HITPART.Touched:connect(addMoney)



0
Have you tried taking the function addMoney() out of your PlayerAdded one? SquirreIOnToast 309 — 10y
0
^ Yes, you probably want to take it out of the 'PlayerAdded' Function. tanzane 100 — 10y
0
How do i get the money value outside of the main function though? creepyzmanrules 0 — 10y

2 answers

Log in to vote
0
Answered by 10 years ago

Try this. If it works, I'll explain it.

game.Players.PlayerAdded:connect(function(player)
    local leaderstats = Instance.new("IntValue",player)
    leaderstats.Name = "leaderstats"
    local money = Instance.new("IntValue", leaderstats)
    money.Name = "Money"
    money.Value = 0
end)

function addMoney(b)
    if b.Name == "MONEYBRICK" then --Is "b" a nil variable
        money.Value = money.Value + 5
        if game.Workspace.UPGRADE1.Touched and b.Name == "MONEYBRICK" then
        money.Value = money.Value + 5
        end
    end
end
function buyupgrade1()
    if money.Value >= 50 then
        money.Value = money.Value - 50
local c = game.Lighting.UPGRADE1:Clone()
    wait(.5)
    c.Parent = game.Workspace
    game.Workspace.pp:Destroy()
    c.Transparency = 0.7
    wait(1)
    c.Transparency = 0.5
    wait(1)
    c.Transparency = 0.3
    wait(1)
    c.Transparency = 0 
    end
end

game.Workspace.pp.Touched:connect(buyupgrade1)
game.Workspace.HITPART.Touched:connect(addMoney)
0
Its not working,'money' isnt declared so i know that is 1 problem. But im still not too sure exactly what is wrong because i cant get the leaderstats from players for some reason. creepyzmanrules 0 — 10y
0
Oh, it was returning a nil value and also said disconnected because of exception creepyzmanrules 0 — 10y
Ad
Log in to vote
0
Answered by 10 years ago

Thanks for everyones reponses, I got the problem fixed by removing some of the code from the main function. Lots of lessons learned here :P

Answer this question