Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

My script doesn't seem to be working?

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)



3 comments

0

Have you tried taking the function addMoney() out of your PlayerAdded one?

0

^ Yes, you probably want to take it out of the 'PlayerAdded' Function.

0

How do i get the money value outside of the main function though?

2 answers

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)

2 comments

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.

0

Oh, it was returning a nil value and also said disconnected because of exception

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

This discussion is preserved as it was. New answers, comments, and votes are closed.