Once a player has purchased a gamepass, a sound is supposed to play and I want a particle effect to appear on the player. However, none of this is working…
Any ideas why?
Server script:
local purchaseEffect = game:GetService("ServerStorage").Effects.DonationEffect.Attachment:Clone()
purchaseEffect.Parent = workspace[winner.Name].Head
local sound = workspace.Sounds.Purchase
local sound1 = sound:Clone()
sound1.Parent = workspace:FindFirstChild(loserPlayer.Name).Head
sound1:Play()
sound1.Ended:Connect(function()
sound1:Destroy()
end)
task.wait(2)
purchaseEffect:Destroy()
-- Check if the winner and loserPlayer exist
if workspace:FindFirstChild(winner.Name) and workspace:FindFirstChild(loserPlayer.Name) then
-- Check if the DonationEffect and Purchase sound exist
if game:GetService("ServerStorage").Effects:FindFirstChild("DonationEffect") and workspace.Sounds:FindFirstChild("Purchase") then
local purchaseEffect = game:GetService("ServerStorage").Effects.DonationEffect.Attachment:Clone()
purchaseEffect.Parent = workspace[winner.Name].Head
local sound = workspace.Sounds.Purchase
local sound1 = sound:Clone()
sound1.Parent = workspace:FindFirstChild(loserPlayer.Name).Head
sound1:Play()
sound1.Ended:Connect(function()
sound1:Destroy()
end)
task.wait(2)
if purchaseEffect then
purchaseEffect:Destroy()
end
else
print("DonationEffect or Purchase sound not found in the game.")
end
else
print("Winner or loserPlayer not found in the workspace.")
end
This script includes checks to ensure that the winner, loserPlayer, DonationEffect, and Purchase sound all exist before they are used. If any of these elements do not exist, a message will be printed to the output window in Studio. This can help you solve any issues with missing elements.
Side note:
This is going to create a connection for each which may lead to memory leaks. I would suggest changing :Connect() to :Once() so the connection is disconnected after it has been used.