Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I find a local playertool by name?

Asked by 1 year ago

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)

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. manith513 121 — 1y

1 answer

Log in to vote
0
Answered by 1 year ago
Edited 1 year ago
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")

Ad

Answer this question