Leaderstats not showing count visually?

So I have a script, where if a player has teleport data, it will give the amount of coins to them. I am printing out the player’s leaderstats coin value before and after giving it, it does print the money out properly. BUT. The leaderstats coins value doesn’t even update, it stays at 0. I know this problem has NOTHING to do with my teleport data script, because simply ADDING the coins without the teleport doesn’t work. Here are some images.


printing out the coins value before and after
Screenshot 2023-12-26 151226
leaderstats after updating

Where is the code that does this?

here’s my script.

game.Players.PlayerAdded:Connect(function(plr)

	plr.CharacterAdded:Connect(function(char)
		for i, object in ipairs(char:GetDescendants()) do
			if object:IsA("BasePart") then
				object.CollisionGroup = "Player"
				object.CanQuery = false
			end
		end

	end)

	local joinData = plr:GetJoinData()
	local tpData = joinData.TeleportData

	if tpData and tpData.Coins then
		print(plr, "rejoined from a match and has earned", tpData.Coins," coins. It has been added to their balance.")
		print(plr:WaitForChild("leaderstats").Coins.Value)
		plr:WaitForChild("leaderstats").Coins.Value = plr:WaitForChild("leaderstats").Coins.Value + tpData.Coins
		print(plr:WaitForChild("leaderstats").Coins.Value)
	else
		for i = 1,5 do
			if tpData and tpData.Coins then
				print(plr, "rejoined from a match and has earned", tpData.Coins," coins. It has been added to their balance.")
				print(plr:WaitForChild("leaderstats").Coins.Value)
				plr:WaitForChild("leaderstats").Coins.Value = plr:WaitForChild("leaderstats").Coins.Value + tpData.Coins
				print(plr:WaitForChild("leaderstats").Coins.Value)
			end
			wait(0.1)
		end
	end
end)


Are you sure that the tpData is an int?

yes, the data i send from the other place is exactly the same as the one in the main game.

Well, there is an int INSIDE it, and that’s “Coins”

try doing tpData.Coins.Value instead of tpData.Coins since coins is not a value

attempt to index number with ‘Value’

this is the error i got.

i think it is becuase of your joinData() being nil,so since this is teleport service,you need the game ID as tpData.Watch the video about teleport service(related to coins value collection)

probably not because it errors out nothing and prints out everything perfectly when I simply do tpData.Coins. the problem is showing it on my default roblox leaderstats.

Edit: I’ll find a vid.

So, are you saying when I set my teleport data, I need to add in the place ID for the main game?

yes,otheriwse they do not know where it is

so is this what I do?

local st = require(script.Parent.SafeTeleport)

game.ReplicatedStorage.Events.TeleportToPlace.OnServerEvent:Connect(function(plr, placeId, coinsToGive)
	
	local options = Instance.new("TeleportOptions")
	options:SetTeleportData({
		["Coins"] = coinsToGive,
		["PlaceID"] = 15189660180
	})
	
	st(placeId, {plr}, options)
end)

you are on the right track(follow the video and you should be able to solve it

well, i didn’t gain much info from the video, but i did learn that for some reason, when I print everything inside of tpData, it prints, nil, and nil. I’m still pretty confused since it still says there’s 6 coins being added, even though it should be saying nil coins added, or even erroring the script.