Ad
Log in to vote
0

how would I make a proximity prompt do something depending on if they have a tool equipped?

Asked by 6 days ago

hello, I am trying to make a game where if you have a tool equipped and you activate a proximity prompt then it will give you one outcome but if you don't have the tool equipped then it will give you a different outcome.

Here is the code inside the tool:

script.parent.Equipped:Connect(function()
    _G.equipped = true
end)

script.parent.Unequipped:Connect(function()
    _G.equipped = false
end)

Here is the code inside of the part with the proximity prompt:

script.Parent.ProximityPrompt.TriggerEnded:Connect(function(player)
    if _G.equipped == true then
        print("outcome 1")
    else
        print("outcome 2")
    end
end)

If anybody could help, that would be great! Thanks!

1 answer

Log in to vote
0
Answered by 5 days ago
Edited 5 days ago
local SpecificTools = {
    YourToolName
}

script.Parent.ProximityPrompt.Triggered:Connect(function(player)
    local character = player.Character

    if character:FindFirstChildOfClass("Tool") then -- Checks if a player has a tool equipped.
        if table.find(SpecificTools, character:FindFirstChildOfClass("Tool").Name) then
            print("outcome 1")
        else
            print("outcome 2")
        end
    else
        print("outcome 2")
    end
end)

EDITED

0
Oh and i mispelled Triggered SEAN_YT213 104 — 5d
0
yea, I'm trying to make it for a specific tool so that prob wont help Borkingforlife 9 — 5d
0
I helped something with a similiar thing so ill edit my comment to that code SEAN_YT213 104 — 5d
0
I've edited it now. SEAN_YT213 104 — 5d
View all comments (3 more)
0
if I understood correctly, theres no script inside of the tool and thats the script inside the proximity prompt part, right? bc it doesn't work. thx for trying to help anyway! Borkingforlife 9 — 5d
0
Yeah SEAN_YT213 104 — 5d
0
Just put your tool name in the table, it works for me. SEAN_YT213 104 — 5d
Ad

Answer this question