Hello, the lost people,
I have a problem with interact item script. I try to detect the person who click the item have tag “Player”. There are no error at the output.
Item Script:
local CollectionService = game:GetService("CollectionService")
local toolTips = {
RedKey = "Unlock red lock",
YellowKey = "Unlock yellow lock",
GreenKey = "Unlock green lock",
BlueKey = "Unlock blue lock",
Crowbar = "Use to break plank",
Wrench = "Use to fix switch"
}
local function interact(item, player)
local checkBackpack = player.Backpack:FindFirstChildWhichIsA("Tool")
local checkCharacter = player.Character:FindFirstChildWhichIsA("Tool")
local character = game.Players:GetPlayerFromCharacter(player.Character)
if checkBackpack or checkCharacter then
local oldItem = checkBackpack or checkCharacter
oldItem.Handle.Detector.MaxActivationDistance = 23
oldItem.Parent = item.Parent
oldItem.Handle.CanTouch = false
oldItem.Handle.Anchored = true
oldItem.Handle.CFrame = item.Handle.CFrame * CFrame.Angles(0, math.rad(45), 0)
end
item.Handle.Anchored = false
item.Handle.CanTouch = true
item.Parent = player.Character
end
for _, item in pairs(CollectionService:GetTagged("Item")) do
item.Handle.Detector.MouseClick:Connect(function(player)
local character = player.Character
if CollectionService:HasTag(character, "Player") then
if character and character:WaitForChild("Humanoid").Health > 0 then
item.Handle.Detector.MaxActivationDistance = 0
interact(item, player)
end
end
end)
item.ToolTip = toolTips[item.Name]
end