-
I want to understand why my script is not working
-
I have this script I am trying to emit particles by script upon purchase of diamonds
I have the script full of debugging and still the particles are not showing at all.
Even though the script is working as intended based on the output.
I know this might be to easy for a lot of you guys but I’m new to scripting and was looking for answers.
Help is appreciated!
Script :
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local player = Players.LocalPlayer
local diamondShopFrame = player.PlayerGui:WaitForChild("DiamondShop"):WaitForChild("DiamondShopFrame")
local shopScrollingFrame = diamondShopFrame:WaitForChild("ShopScrollingFrame")
-- Effects references
local effectsFolder = ReplicatedStorage:WaitForChild("Effects")
local diamondAttachmentTemplate = effectsFolder:WaitForChild("DiamondPurchase"):WaitForChild("DiamondAttachment")
local diamondFalling = diamondAttachmentTemplate:WaitForChild("DiamondFalling")
local fireworks = diamondAttachmentTemplate:WaitForChild("Fireworks")
local blingSound = diamondFalling:WaitForChild("Bling")
local launchSound = fireworks:WaitForChild("Launch")
local boomSound = fireworks:WaitForChild("Boom")
-- Developer product IDs
local productIds = {
[2000] = 2689140779, -- 100 Robux for 2000 Diamonds
[5000] = 2689140778, -- 250 Robux for 5000 Diamonds
[15000] = 2689140776, -- 750 Robux for 15000 Diamonds
[50000] = 2689140777, -- 1500 Robux for 50000 Diamonds
}
-- Function to handle button clicks inside the ShopScrollingFrame
local function onButtonClick(diamondAmount)
local productId = productIds[diamondAmount]
if productId then
print("[DEBUG] Player clicked to purchase", diamondAmount, "diamonds with product ID:", productId)
MarketplaceService:PromptProductPurchase(player, productId)
else
warn("[DEBUG] Invalid diamond amount or product ID for:", diamondAmount)
end
end
-- Attach button click events to buttons inside ShopScrollingFrame
shopScrollingFrame:WaitForChild("2000Diamonds").MouseButton1Click:Connect(function()
print("[DEBUG] 2000 Diamonds button clicked.")
onButtonClick(2000)
end)
shopScrollingFrame:WaitForChild("5000Diamonds").MouseButton1Click:Connect(function()
print("[DEBUG] 5000 Diamonds button clicked.")
onButtonClick(5000)
end)
shopScrollingFrame:WaitForChild("15000Diamonds").MouseButton1Click:Connect(function()
print("[DEBUG] 15000 Diamonds button clicked.")
onButtonClick(15000)
end)
shopScrollingFrame:WaitForChild("50000Diamonds").MouseButton1Click:Connect(function()
print("[DEBUG] 50000 Diamonds button clicked.")
onButtonClick(50000)
end)
-- Function to play the particle effects as a purchase confirmation
local function playParticleEffects()
print("[DEBUG] Starting particle effects.")
local character = player.Character or player.CharacterAdded:Wait()
local torso = character:FindFirstChild("Torso")
if not torso then
warn("[DEBUG] Torso not found for player:", player.Name)
return
end
print("[DEBUG] Found Torso for player:", player.Name)
-- Clone and attach the DiamondAttachment
local diamondAttachmentClone = diamondAttachmentTemplate:Clone()
diamondAttachmentClone.Parent = torso
diamondAttachmentClone.Position = Vector3.new(0, 0, 0) -- Center it relative to torso
print("[DEBUG] DiamondAttachment cloned and parented to Torso.")
-- Emit particles
print("[DEBUG] Attempting to emit DiamondFalling particles.")
diamondFalling:Emit(10)
print("[DEBUG] DiamondFalling particles emitted.")
print("[DEBUG] Attempting to emit Fireworks particles.")
fireworks:Emit(10)
print("[DEBUG] Fireworks particles emitted.")
-- Cleanup after effects
task.delay(3, function()
print("[DEBUG] Cleaning up DiamondAttachment.")
diamondAttachmentClone:Destroy()
end)
end
-- Function to handle purchase success
MarketplaceService.PromptProductPurchaseFinished:Connect(function(finishedUserId, productId, wasPurchased)
print("[DEBUG] PromptProductPurchaseFinished triggered for User ID:", finishedUserId, "Product ID:", productId, "Was Purchased:", wasPurchased)
local finishedPlayer = Players:GetPlayerByUserId(finishedUserId)
if not finishedPlayer then
warn("[DEBUG] Could not find player for User ID:", finishedUserId)
return
end
if finishedPlayer == player and wasPurchased then
print("[DEBUG] Purchase successful for product ID:", productId)
-- Close the DiamondShopFrame
diamondShopFrame.Visible = false
print("[DEBUG] DiamondShopFrame closed.")
-- Trigger particle effects as confirmation
playParticleEffects()
-- Add diamonds to the player's leaderstats
local updateDiamonds = ReplicatedStorage.RemoteFunctions:WaitForChild("UpdateDiamonds")
local success = updateDiamonds:InvokeServer(productId)
if success then
print("[DEBUG] Successfully updated diamonds on the server.")
else
warn("[DEBUG] Failed to update diamonds on the server.")
end
elseif not wasPurchased then
print("[DEBUG] Purchase was canceled or failed.")
end
end)