I’m attempting to make an interaction system by pressing “H”, in which will function an event to clone the player’s tool to the other player and delete the original player’s tool. For this to function, I made a BillboardUi in which showcases the player’s name, role, what tool they’re about to receive (as shown in the image below) with an expected magnitude distance (they need to be 5 studs close). However, this doesn’t seem to function as intended, is there a reason for this?
--[ Variables
local rep = game:GetService("ReplicatedStorage")
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local handUi = char:WaitForChild("HandToUi")
local plrs = game:GetService("Players")
local hand = false
local ts = game:GetService("TweenService")
local uip = game:GetService("UserInputService")
--[ Setup
-- taking players individually and tools in the menu folder
while wait() do
for _, i in ipairs(plrs:GetChildren()) do
for _, c in pairs(rep:WaitForChild("Menu"):GetChildren()) do
local iChar = i.Character
local iHand = i.Character:WaitForChild("HandToUi").MainFrame
-- actively checking their backpack and magnitude
for _, v in pairs(plr.Backpack:GetChildren()) do
local magnitude = (iChar:WaitForChild("HumanoidRootPart").Position - char:WaitForChild("HumanoidRootPart").Position).Magnitude -- measuring magnitude between all humanoidrootpart from other players to the local player
if (magnitude <= 5) and (c.Name.Equipped) then -- 2 characters close by and the local player has tool equipped from the menu folder
hand = true
local moveIn = ts:Create(iHand, TweenInfo.new(.6, Enum.EasingStyle.Quart, Enum.EasingDirection.Out, 0, false, 0), {Position = UDim2.new(0, 0, 0, 0)})
iHand.tool.Text = c.Name -- changing frame's tool text to the tool they're holding
moveIn:Play()
uip.InputBegan:Connect(function(key)
if (key.Keycode == Enum.KeyCode.H) and hand then
local clonedTool = c:Clone()
clonedTool.Parent = i.Backpack
c:Destroy()
print(plr.Name.." has given ["..clonedTool.."] to "..i.Name)
end
end)
elseif (magnitude >= 5) or not (c.Name.Equipped) then
hand = false
local moveOut = ts:Create(iHand, TweenInfo.new(.6, Enum.EasingStyle.Quart, Enum.EasingDirection.In, 0, false, 0), {Position = UDim2.new(-2, 0, 0, 0)})
moveOut:Play()
end
end
end
end
end
Image of the Billboard: