I'm pretty new to Lua and Roblox Studio, so with my current knowledge I wrote this code that is supposed to detect if a tool is equipped or unequipped by the player. I have two scripts, one under the tool which works fine:
local tool = script.Parent
local handle = tool:WaitForChild("Handle")
local prompt = game.Workspace.Testpart.ProximityPrompt
local equiped = false
tool.Equipped:Connect(function()
print("Equipped")
equiped = true
end)
tool.Unequipped:Connect(function()
print("Unequipped")
equiped = false
end)
prompt.Triggered:Connect(function(player)
if equiped == true then
print("Active")
elseif equiped == false then
print("Inactive")
end
end)
And another one under the proximity prompt which doesn't detect if the tool is equipped or not:
local prompt = script.Parent
local equiped = false
local players = game.Players
local backpack = nil
local tool = nil
players.PlayerAdded:Connect(function(player)
backpack = player.Backpack
tool = backpack.Tool
print("Player added")
tool.Equipped:Connect(function()
print("Equipped2")
equiped = true
end)
tool.Unequipped:Connect(function()
print("Unequipped2")
equiped = false
end)
end)
prompt.Triggered:Connect(function(player)
if equiped == true then
print("Active2")
end
if equiped == false then
print("Inactive2")
end
end)
Any help is appreciated, thanks!