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

leaderstats value is doing weird?

So I'm working on a lab game with research points leaderstats. If I'm making a script where a leaderstat needs to be decreased, it decreases not with 20 like I said in the script, but with way more. For example. If I buy a product requires 20 points, I give the player the product, and points are gone, but not the amount of points I gave the script. There's also a new bool instance thing but that works fine.

Here's the script:

script.Parent.MouseButton1Click:Connect(function() local plr = script.Parent.Parent.Parent.Parent.Parent plr.leaderstats.Research.Value = plr.leaderstats.Research.Value - 20 local bool = Instance.new("BoolValue",plr) bool.Value = true bool.Name = "HasTestSubject" end)

It's in a server script. I hope somebody knows what's wrong.

4 comments

0

I suggest doing game.Players.LocalPlayer instead of local plr = script.Parent.Parent.Parent.Parent.Parent

0

I can't since it's a server script.

0

You should put an if statement to see if the player already owns it or use a debounce as ShutokouBattle mentioned

0

"leaderstats value is doing weird?" lmao

2 answers

Try adding a "debounce". This will prevent an event from firing lots of times instead of one.

local deb = false
script.Parent.MouseButton1Click:Connect(function()
if deb == false then
deb = true
local plr = script.Parent.Parent.Parent.Parent.Parent  
plr.leaderstats.Research.Value = plr.leaderstats.Research.Value - 20  
local bool = Instance.new(“BoolValue”,plr)  
bool.Value = true  
bool.Name = “HasTestSubject” 
wait(3)
deb = false 
end)

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