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

Why does this leaderstats script not work? (Explanation exceeded the title character limit)

Asked by 6 years ago

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.

0
To use a code block: click on the Code block button then paste your code in between the two lines of "~~~". xPolarium 1388 — 6y

2 answers

Log in to vote
0
Answered by
xPolarium 1388 Moderation Voter
6 years ago
Edited 6 years ago

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)
0
Thank you, it worked! sesamert16 31 — 6y
Ad
Log in to vote
-2
Answered by 6 years ago

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.

0
The game is still in development. sesamert16 31 — 6y
0
This answer isn't a solution so it should stay in the comments. xPolarium 1388 — 6y
0
Well, I can still help out, but I could use all help that's needed if you invite me. StarMarine614Classic 14 — 6y

Answer this question