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

leaderstats value is doing weird?

Asked by
H3kken -4
5 years ago

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.

0
I suggest doing game.Players.LocalPlayer instead of local plr = script.Parent.Parent.Parent.Parent.Parent SuperSamyGamer 316 — 5y
0
I can't since it's a server script. H3kken -4 — 5y
0
You should put an if statement to see if the player already owns it or use a debounce as ShutokouBattle mentioned Fad99 286 — 5y
0
"leaderstats value is doing weird?" lmao Fad99 286 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago

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)
Ad
Log in to vote
0
Answered by
H3kken -4
5 years ago

Neither a debounce or a checker if the player already owns it work. Screenshot of the script: https://imgur.com/a/y3h8I0C Video of what the script does: https://youtu.be/3HAzXDoGfFs (In the video look at the leaderstats)

Answer this question