The question is very self explanitory, but I’m currently trying to make it so my Draggable Health Bar doesn’t drag when a player is using the mobile thumbstick, or jumping button on Mobile devices.
How would I go about doing this? I’m assuming it would be the UserInputService, but I’m not sure if I need to create a tag list of things that if pressed will ignore the health bar or something much more simple.
Code currently made
local UIS = game:GetService("UserInputService");local players = game:GetService("Players")
local TopBar = script.Parent;local Camera = game.Workspace:WaitForChild("Camera");local DragMousePosition,FramePosition;local Draggable = false
local UserId,thumbType,thumbSize = game.Players.LocalPlayer.UserId,Enum.ThumbnailType.HeadShot,Enum.ThumbnailSize.Size420x420;local content, isReady = game:GetService("Players"):GetUserThumbnailAsync(UserId,thumbType,thumbSize)
local player = players.LocalPlayer;local char = player.Character or player.CharacterAdded:Wait();local hum = char:WaitForChild("Humanoid")
local Digit = script.Parent:WaitForChild("Holder").Digits;local MaxDigit = script.Parent.MaxHPDisplay.MaxDigits;local Healthbar = script.Parent:WaitForChild("Holder").Healthbar;local Avatar = script.Parent.Avatar_Icon
local colorHealthMax = Color3.fromRGB(0,255,0);local colorHealthMid = Color3.fromRGB(255,200,0);local colorHealthMin = Color3.fromRGB(255,0,0)
Avatar.Image = content
TopBar.InputBegan:Connect(function(input)
if UIS and UIS:GetFocusedTextBox() == nil then
if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
Draggable = true
DragMousePosition = Vector2.new(input.Position.X, input.Position.Y)
FramePosition = Vector2.new(TopBar.Position.X.Scale,TopBar.Position.Y.Scale)
end
end
end)
TopBar.InputEnded:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
Draggable = false
end
end)
UIS.InputChanged:Connect(function(input)
if Draggable == true then
local NewPosition = FramePosition + ((Vector2.new(input.Position.X,input.Position.Y) - DragMousePosition) / Camera.ViewportSize)
TopBar.Position = UDim2.new(NewPosition.X,0, NewPosition.Y,0)
end
end)