Heya! So I’ve been working on a kit along with Twin (@TwinPlayzDev) and we’ve been wondering about this bug for quite a while going back and forth trying to find the root cause.
I did not find a root cause but I did add a bunch of sanity checks… yet I found out that for some reason this only works when you’re playtesting alone.
Even if you teamtest and buy your own product, it wouldn’t do anything.
Attached code:
local MarketplaceService = game:GetService("MarketplaceService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local AddValueEvent = ReplicatedStorage.Events.AddValue
local ChatEvent = ReplicatedStorage.Events.ChatMsg
MarketplaceService.PromptPurchaseFinished:Connect(function(player, assetId, isPurchased)
if isPurchased then
local data = MarketplaceService:GetProductInfo(assetId, Enum.InfoType.Asset)
if data then
if player then
if player.leaderstats.Donated then
if tonumber(data.PriceInRobux) then
player.leaderstats.Donated.Value += tonumber(data.PriceInRobux)
local DonatedValue = player.leaderstats.Donated.Value
AddValueEvent:Fire(player.userId, tonumber(data.PriceInRobux), "Donated")
end
end
end
local GotDonatedName = data.Creator.Name
local Stands = workspace:FindFirstChild("Stands")
local StandDescendants = Stands:GetDescendants()
ChatEvent:FireAllClients(GotDonatedName, player.Name, data.PriceInRobux)
if game:GetService("Players")[GotDonatedName] then
local GotDonatedPlr = game:GetService("Players")[GotDonatedName]
if GotDonatedPlr.leaderstats.Raised then
if tonumber(data.PriceInRobux) then
GotDonatedPlr.leaderstats.Raised.Value += tonumber(data.PriceInRobux)
AddValueEvent:Fire(GotDonatedPlr.userId, tonumber(data.PriceInRobux), "Raised")
for _, Object in ipairs(StandDescendants) do
if Object:IsA("TextLabel") and Object.Name == "MoneyRaised" and Object.Parent.Parent.Parent.Parent.Proximity.Owner.Value == GotDonatedName then
local Amount = GotDonatedPlr.leaderstats.Raised.Value
Object.Text = Amount .. "$ Raised"
elseif Object:IsA("ParticleEmitter") and Object.Name == "Money" and Object.Parent.Parent.Proximity.Owner.Value == GotDonatedName then
Object:Emit(15)
local Sound = Object.Parent:FindFirstChildOfClass("Sound")
Sound:Play()
end
end
end
end
end
end
end
end)
MarketplaceService.PromptGamePassPurchaseFinished:Connect(function(player, assetId, isPurchased)
if isPurchased then
local data = MarketplaceService:GetProductInfo(assetId, Enum.InfoType.Asset)
if data then
if player then
if player.leaderstats.Donated then
if tonumber(data.PriceInRobux) then
player.leaderstats.Donated.Value += tonumber(data.PriceInRobux)
local DonatedValue = player.leaderstats.Donated.Value
AddValueEvent:Fire(player.userId, tonumber(data.PriceInRobux), "Donated")
end
end
end
local GotDonatedName = data.Creator.Name
local Stands = workspace:FindFirstChild("Stands")
local StandDescendants = Stands:GetDescendants()
ChatEvent:FireAllClients(GotDonatedName, player.Name, data.PriceInRobux)
if game:GetService("Players")[GotDonatedName] then
local GotDonatedPlr = game:GetService("Players")[GotDonatedName]
if GotDonatedPlr.leaderstats.Raised then
if tonumber(data.PriceInRobux) then
GotDonatedPlr.leaderstats.Raised.Value += tonumber(data.PriceInRobux)
AddValueEvent:Fire(GotDonatedPlr.userId, tonumber(data.PriceInRobux), "Raised")
for _, Object in ipairs(StandDescendants) do
if Object:IsA("TextLabel") and Object.Name == "MoneyRaised" and Object.Parent.Parent.Parent.Parent.Proximity.Owner.Value == GotDonatedName then
local Amount = GotDonatedPlr.leaderstats.Raised.Value
Object.Text = Amount .. "$ Raised"
elseif Object:IsA("ParticleEmitter") and Object.Name == "Money" and Object.Parent.Parent.Proximity.Owner.Value == GotDonatedName then
Object:Emit(15)
local Sound = Object.Parent:FindFirstChildOfClass("Sound")
Sound:Play()
end
end
end
end
end
end
end
end)
Attached place file:
PlsDonateFix v.3.286.rbxl (314,6 KB)
I’ve had quite some reports of issues regarding this code and they all return the same;
ServerScriptService.NewStatsHandler:Line ( this line below ): attempt to perform arithmetic add on number and nil
player.leaderstats.Donated.Value += tonumber(data.PriceInRobux)
Help would be gladly appreciated, thank you!!