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

Give money in leaderboard when you touch a brick?

So pretty much, I have a leaderboard script so when you touch a brick named Robux, it will add +1 your Money score. But it doesn't seem to be working. Could you help me fix it?

Heres the script, btw

game.Players.PlayerAdded:connect(function(player) --We create a function that will execute when PlayerAdded fires.
     local leaderstats = Instance.new("Model", player) --We insert an Model into the the new player (player)
     leaderstats.Name = "leaderstats"
 end) --closes function


game.Players.PlayerAdded:connect(function(player)
     local leaderstats = Instance.new("Model", player)
     leaderstats.Name = "leaderstats"
 
     local robux = Instance.new("IntValue", leaderstats) --We instance a new IntValue as a child of 'leaderstats'
     money.Name = "Robux" --this is the name you want the leader-stat to be when it shows up in-game.
     money.Value = 15 --this is the value of money the new player starts out with.
 end)


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
end)
 

while wait(5) do 
    for _,Player in pairs(game.Players:GetPlayers()) do
        if Player:FindFirstChild("leaderstats") then
            Player.leaderstats.Money.Value = Player.leaderstats.Money.Value +1
        end
    end
end


local brick = Workspace.Robux -- Store a reference to the brick.
 
function onTouch(part) -- The function that runs when the part is touched.
	brick:remove()
            Player.leaderstats.Money.Value = Player.leaderstats.Money.Value +1

	 
end 
 
brick.Touched:connect(onTouch) -- The line that connects the function to the event.

2 comments

0

Also the top part is more of just adding the leaderboard or other features. I just kept it incase you needed it or not.

0

You have lots of things wrong in your script. You even did "money.Name = "Robux

3 answers

This is how I would do it. Also, It would help if you give me the results on the Output window. (Or post this in a place, as I know how to see output in any place)

Workspace.Robux.Touched:connect(function()
	brick:destroy() --remove() has been deprecated, do NOT use it
	Player.leaderstats.Money.Value = Player.leaderstats.Money.Value + 1
end)

1 comment

0

Thanks, but when I try to fix the script with that, I just get this output. 17:19:12.827 - Workspace.Script:12: attempt to index global 'money' (a nil value) 17:19:12.828 - Stack Begin 17:19:12.828 - Script 'Workspace.Script', Line 12 17:19:12.829 - Stack End 17:19:12.829 - Disconnected event because of exception Help pleas

After trying to do it I figured it out.

local brick = script.Parent

function onTouched(hit)
	for i,player in ipairs(game.Players:GetPlayers()) do
		if player.Character then
			local stat = player:FindFirstChild("leaderstats")
			if stat then
				player.leaderstats.Money.Value = player.leaderstats.Money.Value +1
				brick:Destroy()
			end
		end
	end
end


brick.Touched:connect(onTouched)

1 comment

0

He means the player who touched the brick.

i have tried all of them, none of them work, my leaderstat is Money and my part drop name is MoneyMaker plz help

2 comments

0

i mean the brick that is being dropped is called MoneyMaker

0

also the part only goes on the part, gives me one money stays there and the rest come and give me no money

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