I have this script where it detects when the player joins, and if it has teleport data, it should add it to their leaderstats. Although it is printing in the developer console, it doesn’t give the coins to thier balance. Any help?
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 * 10) / 10)," coins. It has been added to their balance.")
plr:WaitForChild("leaderstats").Coins.Value += tpData.Coins
end
end)
this is my teleport script.
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
})
st(placeId, {plr}, options)
end)
UPDATE: It is adding the coins, just the leaderstats doesn’t show it visually for some reason.