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

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

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

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

7 comments

0

Oh and i mispelled Triggered

0

yea, I'm trying to make it for a specific tool so that prob wont help

0

I helped something with a similiar thing so ill edit my comment to that code

0

I've edited it now.

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!

0

Yeah

0

Just put your tool name in the table, it works for me.

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