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.
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)
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)
i have tried all of them, none of them work, my leaderstat is Money and my part drop name is MoneyMaker plz help