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

I am trying to change a leaderboard value but it doesn't work. Ideas?

I am making a zombie defense tycoon and I want to subtract the players value by 250 but everytime it does that the credits values just goes to -250 even tough I started out with 1,500.

local serverstorage = game:GetService("ServerStorage")

local conveyer2 = serverstorage:WaitForChild("Conveyers").Conveyer2
local conveyer3 = serverstorage:WaitForChild("Conveyers").Conveyer3

local debounce = false

local PrimaryCFrame = CFrame.new(-166.8,3.2,10.1)

function CloneCollector()
	local collector = workspace:FindFirstChild("Collector1")
	collector.PrimaryPart = collector:FindFirstChild("BrickCollector")
	local clone = collector:Clone()
	clone:SetPrimaryPartCFrame(PrimaryCFrame)
	clone.Parent = workspace
	collector:Destroy()
end

function CloneConveyer()
	local conveyer2 = conveyer2:Clone()
	conveyer2.Parent = workspace
	local conveyer3 = conveyer3:Clone()
	conveyer3.Parent = workspace
end

script.Parent.Touched:Connect(function(hit)
 if debounce == false then
	debounce = true
	local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
	if not player then
	   return
	end
	if true then
		player.leaderstats.Credits.Value = player.leaderstats.Credits.Value - 250
		CloneCollector()
		CloneConveyer()
		script.Parent:Destroy()
		wait(1.5)
		debounce = false
	else
		script.Parent.TextButton.NameText.Text = "Not Enough Credits"
		script.Parent.TextButton.PriceText.Text = ""
		wait(1.5)
		script.Parent.TextButton.NameText.Text = "Expand Conveyer"
		script.Parent.TextButton.PriceText.Text = "250 Credits"
		debounce = false
	end
 end
end)


3 comments

0

You aren't checking if they have 250 credits before subtracting them. You're just checking if 'true'.

0

Exactly what Dinoz said.

0

I've made an answer in case you didn't understand. Hopefully it's cleared almost all of your confusion about your script.

1 answer

Question : I am trying to change a leaderboard value but it doesnt work. Ideas?

The reason why it isn't working is because on line 33 you're just checking if the value is true, you aren't checking how much credits the player has, so the script is confused and just runs the best guess it can due to your information, which is the value, -250.

LUA is very case-sensitive so it won't just check the players credits like most other languages would. You have to program it to check the language, hence why LUA is also limited.

if player.leaderstats.Credits.Value >= 250 then
	player.leaderstats.Credits.Value = player.leaderstats.Credits.Value - 250
end

Hopefully I've helped!

If I have helped, it'd be much appreciated if you clicked 'Accept Answer', also letting me know I've helped you! Thanks!

3 comments

0

you guys are nt getting it

0

Okay, well could you please explain better so I can understand? Thanks!

0

And at least try the script, it may fix your issue. Reply once you've tried the script.

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