I have a script where, if a block is touched, all of the leaderstats reset to 0 except for Money. Money's value is supposed to become the quotient of the value of Views divided by 1000. The resetting of the values part works fine, but Money's value stays at 0. Does anyone know why? Since I don't know how to add those code block things I'll link a screenshot of my code here: http://prntscr.com/hv82hi You'll notice that in the screenshot some of the code on line 4 is cut off. After player.leaderstats.Views it says .Value / 1000.
Your full code:
script.Parent.Touched:Connect(function() for _, player in pairs(game.Players:GetPlayers()) do if player:FindFirstChild("leaderstats") then player.leaderstats.Money.Value = player.leaderstats.Money.Value + players.leaderstats.Views.Value / 1000 player.leaderstats.Views.Value = 0 player.leaderstats.Subscribers.Value = 0 player.leaderstats.Videos.Value = 0 end end end)
One of the issues I can think of is that you might be dividing a 0 since you set Views to 0. A zero divided by any number is obviously 0. This is probably happening because you don't have a cool down of when the player can touch the part.
Try this following code or make sure what you are adding doesn't come out to be a 0 then divide it.
local debounce = true --Search debounces on roblox wiki if you don't know about it script.Parent.Touched:Connect(function() for _, player in pairs(game.Players:GetPlayers()) do if player:FindFirstChild("leaderstats") and debounce then --Debounce check debounce = false --turn off debounce player.leaderstats.Money.Value = player.leaderstats.Money.Value + players.leaderstats.Views.Value / 1000 player.leaderstats.Views.Value = 0 player.leaderstats.Subscribers.Value = 0 player.leaderstats.Videos.Value = 0 wait(3) --Our set cooldown debounce = true --Turn on the debounce to allow the player to touch again end end end)
Hello, invite me to your game and I will fix your problem. I don't know how to exactly explain it, but I'll explain it the best I can.