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

Why doesn't is my script stuck using the old value?

This is a ServerSide SCript

local Debounce = true

script.Parent.Touched:connect(function(Part)
	if Debounce then
		Debounce = false
		script.Parent.Transparency = 1
		local Player = game.Players:GetPlayerFromCharacter(Part.Parent)
		local PlayerTrash = Player.leaderstats.Trash
		local PlayerRebirth = Player.leaderstats.Rebirths
		
		PlayerTrash.Value = PlayerTrash.Value + (PlayerRebirth.Value + 1)
		print((PlayerRebirth.Value + 1))
		wait() script.Parent:Destroy()
	end
end)

it prints out 1 so PlayerRebirth.Value is 0 even thought on leaderboard i says 1

If my rebirth was 1, it would give me 1 Trash but it is supposed to give me 2

3 comments

1

use :Connect() not :connect() but idk the prob

0

what does it print out

0

1

1 answer

✓ Accepted answer

First of all, modifying leaderstats should be handled locally because leaderstats are located in the player's Backpack. Second, you should check to make sure that PlayerRebirth.Value is 1 before you do anything else, because that's where the script is going wrong.

Here is a possible fix:

-- This should be a local script, not a regular script
local Debounce = true

script.Parent.Touched:connect(function(Part)
	if Debounce == false then return end
	Debounce = false
	script.Parent.Transparency = 1
	local Player = game.Players:GetPlayerFromCharacter(Part.Parent)
	local PlayerTrash = Player.leaderstats.Trash
	local PlayerRebirth = Player.leaderstats.Rebirth
	if PlayerRebirth.Value == 1 then -- Here's the fix
		PlayerTrash.Value = PlayerTrash.Value + PlayerRebirth.Value
		print((PlayerTrash.Value) -- should print 2
		wait()
		script.Parent:Destroy()
	end
end)

Feel free to ask any questions you may have.

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