I’d like to make it so that if I have a certain tool (Flashlight) equipped, then the proximity prompt is disabled.
Specific Part of Item Script:
function item.New(location, itemName)
local itemObject = workspace.Items:FindFirstChild(itemName)
if itemObject==nil then
return
end
local objectToDuplicate = (itemObject:IsA("Tool") and itemObject:FindFirstChild("Handle")) or itemObject
local newObject = objectToDuplicate:Clone()
newObject:PivotTo(location.WorldCFrame)
local partToWeldTo = if newObject:IsA("Model") then newObject.PrimaryPart else newObject
if partToWeldTo:IsA("BasePart") then
local weld = Instance.new("WeldConstraint")
weld.Part0 = partToWeldTo
weld.Part1 = location.Parent
weld.Parent = partToWeldTo
end
newObject.Parent = location
local prompt = Instance.new("ProximityPrompt")
prompt.ActionText = ""
prompt.MaxActivationDistance = 5
prompt.Parent = location
prompt.Style = Enum.ProximityPromptStyle.Custom
prompt.Triggered:Connect(function(player)
item.Interact(player, prompt, newObject, itemName)
end)
end
return item
Whole Item Script:
local item = {}
function item.GetItems(includeSpecialItems: boolean): {string}
local itemNames = {}
local itemFolder = workspace.Items
for _,item in itemFolder:GetChildren() do
if item:GetAttribute("IsSpecial") and not includeSpecialItems then
continue
end
table.insert(itemNames, item.Name)
end
return itemNames
end
function item.Interact(player, prompt, template, itemName)
if player.Character then
if itemName == "Key" then
local tool = workspace.Items.Key:Clone()
tool.Parent = player.Character
tool.Handle.KeyJingle:Play()
end
prompt.Enabled = false
template:Destroy()
end
end
function item.New(location, itemName)
local itemObject = workspace.Items:FindFirstChild(itemName)
if itemObject==nil then
return
end
local objectToDuplicate = (itemObject:IsA("Tool") and itemObject:FindFirstChild("Handle")) or itemObject
local newObject = objectToDuplicate:Clone()
newObject:PivotTo(location.WorldCFrame)
local partToWeldTo = if newObject:IsA("Model") then newObject.PrimaryPart else newObject
if partToWeldTo:IsA("BasePart") then
local weld = Instance.new("WeldConstraint")
weld.Part0 = partToWeldTo
weld.Part1 = location.Parent
weld.Parent = partToWeldTo
end
newObject.Parent = location
local prompt = Instance.new("ProximityPrompt")
prompt.ActionText = ""
prompt.MaxActivationDistance = 5
prompt.Parent = location
prompt.Style = Enum.ProximityPromptStyle.Custom
prompt.Triggered:Connect(function(player)
item.Interact(player, prompt, newObject, itemName)
end)
end
return item