Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I find a local playertool by name?

Hello, I have added a proximity prompt to a part and when used, it sells the item you currently have. I made this by creating a "Tools" folder in the proximityprompt, followed by a Boolvalue (Name of tool) and Numbervalue (Price of tool)

So the structure looks like this:

Part

  • Proximityprompt -- Tools (Folder) --- Sword (Boolvalue) ---- Price (Numbervalue)

Now I have been stuck with on prohibitng from selling certain items. Lets say we have a tool named "Sword1", and I want that everything can be sold except for this "Sword1", how should I do that? I have tried with "if..." scripts but I cannot figure out what I am doing wrong.

Below you can find the script.

local prox = script.Parent

prox.Triggered:Connect(function(player)
	for i, tools in pairs(prox.Tools:GetChildren()) do
		if player.Character:FindFirstChild(tools.Name) then
			player.leaderstats.Cash.Value += tools.Price.Value 

			player.Character:FindFirstChild(tools.Name):Destroy()
		end
	end
end)

1 comment

0

Does the code you showed above work? It doesn’t look like it has the prohibiting part that you want to add, if it does work, then I can add the prohibiting part.

1 answer

✓ Accepted answer
local prox = script.Parent

prox.Triggered:Connect(function(player)
    for i, tools in pairs(prox.Tools:GetChildren()) do
        if player.Character:FindFirstChild(tools.Name) and tools.Name ~= "Sword1" then
            player.leaderstats.Cash.Value += tools.Price.Value 

            player.Character:FindFirstChild(tools.Name):Destroy()
        end
    end
end)

i think this is the answer if (and tools.Name ~= "Sword1") dosent work then try (and not tools.Name == "Sword1")

This discussion is preserved as it was. New answers, comments, and votes are closed.