My script isn't working for some reason

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()

image

1 Like

Is the particle enabled? Also, you may want to use :Emit() to emit the particles instantly.

2 Likes

Yes the particles enabled and I just added emit() and it still doesnt work

1 Like

Try this.

-- 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.

3 Likes

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.

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.