Why is my Accessory Remover Proxmity Prompt not working?

My goal here is to remove all accessory of a player who triggered the proximity prompt however my scripts seems to be not working:


local prompt = script.Parent
function onPromptTriggered(triggerPart)
    local player = game.Players:GetPlayerFromCharacter(triggerPart.Parent)
    if player and player.Character then
        for _, accessory in ipairs(player.Character:GetChildren()) do
            if accessory:IsA("Accessory") then
                accessory:Destroy()
            end
        end
    end
end

prompt.Triggered:Connect(onPromptTriggered)

I hope somebody can help since I have not scripted for a while and I am trying again,

You don’t need to use GetPlayerFromCharacter because ProximityPromt passes the player object right away (in game.Players)
You need to do this:

local prompt = script.Parent
function onPromptTriggered(player)
	if player.Character then
		for _, accessory in ipairs(player.Character:GetChildren()) do
			if accessory:IsA("Accessory") then
				accessory:Destroy()
			end
		end
	end
end

prompt.Triggered:Connect(onPromptTriggered)
2 Likes

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