I’m in the process of creating handcuffs that essentially show Images of specific buttons to indicate to cuff within a distance of 8 studs. After researching i found personally using CollectionService would be the best option for this.
My issue is that the BillboardGui is not being Adorned nor Enabled when the player is within the certain distance. I’m not getting any errors in the output and i’m stuck on what to do next. Any help is greatly appreciated.
local CS = game:GetService("CollectionService")
local player = game.Players.LocalPlayer
local cancuff = CS:GetTagged("Cuffable")
local CuffDistance = 8
local PlayerName = ""
local InteractedPlayer = ""
function FindNearest(player, Interaction)
local Distance = player:DistanceFromCharacter(Interaction.Position)
if Distance <= 7 then
return Interaction
end
end
while wait() do
for i,v in pairs(game.Players:GetDescendants()) do
if v and CS:HasTag(v, "InteractionPlayer") and game.Players:GetPlayerFromCharacter(v.Parent) and game.Players:GetPlayerFromCharacter(v.Parent).Name ~=player.Name then
if FindNearest(player, v) and player:DistanceFromCharacter(v.Position) <= 10 and not v:FindFirstChild("InteractionUI") and not Enabled and PlayerName == "" and InteractedPlayer == "" and game.Players:GetPlayerFromCharacter(v.Parent).Character.Humanoid.Health > 0 and player.Character.Humanoid.Health > 0 and player.TeamColor == game.Teams["Victoria Police"].TeamColor and player.CuffingValues.Cuffed.Value ~= true and game.Players:GetPlayerFromCharacter(v.Parent).CuffingValues.Cuffed.Value ~= true then
Enabled = true
local HCUI = script.InteractionUI:Clone()
HCUI.Parent = game.Players:GetPlayerFromCharacter(v.Parent).Character.Torso
HCUI.Image.Visible = true
HCUI.TextLabel.Visible = true
HCUI.Adornee = game.Players:GetPlayerFromCharacter(v.Parent).Character.Torso
InteractedPlayer = game.Players:GetPlayerFromCharacter(v.Parent)
PlayerName = game.Players:GetPlayerFromCharacter(v.Parent).Name
InteractedPlayer.CharacterRemoving:Connect(function()
Enabled = false
InteractedPlayer = ""
PlayerName = ""
end)
elseif game.Players:GetPlayerFromCharacter(v.Parent) and player:DistanceFromCharacter(v.Position) > 11 and v:FindFirstChild("InteractionUI") and Enabled or game.Players:GetPlayerFromCharacter(v.Parent).Character.Humanoid.Health <= 0 or player.Character.Humanoid.Health <= 0 or player.TeamColor ~= game.Teams["Victoria Police"].TeamColor or player.CuffingValues.Cuffed.Value ~= false then
Enabled = false
PlayerName = ""
InteractedPlayer = ""
if game.Players:GetPlayerFromCharacter(v.Parent).Character:FindFirstChild("Torso"):FindFirstChild("InteractionUI") then
game.Players:GetPlayerFromCharacter(v.Parent).Character:FindFirstChild("Torso"):FindFirstChild("InteractionUI"):Destroy()
end
end
end
end
end