I want to make, so that when I equip a tool while a tool is still equipped I interact with proximity prompt
and then it works, basically having a key equipped and unlocking a door
local Player = game.Players.LocalPlayer
wait(1)
local Character = workspace:FindFirstChild(Player.Name)
local BackPack = Player.Backpack
local Proxy = workspace.KeyPart.ProximityPrompt
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Tool = ReplicatedStorage.Tool
local KnobProxy = workspace.MainDoor.Knob.ProximityPrompt
Proxy.Triggered:Connect(function(playerWhoTriggered)
Tool.Parent = playerWhoTriggered.Backpack
Tool.Equipped:Connect(function()
print("ok")
KnobProxy.Triggered:Connect(function()
print("k")
end)
end)
end)
Try this (if this is localscript), here I check if the item is in the player’s hands (in the character, not in the backpack) when using the proximity prompt.
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local BackPack = Player.Backpack
local Proxy = workspace.KeyPart.ProximityPrompt
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Tool = ReplicatedStorage.Tool:Clone()
local KnobProxy = workspace.MainDoor.Knob.ProximityPrompt
Proxy.Triggered:Connect(function()
Tool.Parent = BackPack
end)
KnobProxy.Triggered:Connect(function()
if Tool.Parent.Name==Player.Name then
print("k")
end
end)
works, but your explanation is item is in the player’s hand not in the backpack* I put it in the backpack so the player can have it, also how do you know if it is in the player’s hand this part makes 0 sense to me,
the only way to check if it’s equipped
Also Tool.Parent.Name ==Player.Name
what is this supposed to mean?
The script works, but it’s rng dependent, becoz sometimes I get the key sometimes I don’t.
If the item is equipped, then its parent will be a player character whose name is equal to the player’s name. If it is not equipped, then its parent is a backpack, and the name of the backpack (Backpack) will not be equal to the name of the player.