local UserInputService = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer
local mouse = Player:GetMouse()
local function Collect(Input)
if Input.KeyCode == Enum.KeyCode.F and script.Values.CurrentSelectedPart.Value then
script.Server_Event.Value:FireServer("COLLECT", script.Values.CurrentSelectedPart.Value)
end
end
local function HandleClick()
script.Server_Event.Value:FireServer("NoString", script.Values.MouseTarget.Value)
end
-- Desktop: MouseButton1 click
UserInputService.InputBegan:Connect(function(Input, gameProcessedEvent)
if not gameProcessedEvent then
if Input.UserInputType == Enum.UserInputType.MouseButton1 then
HandleClick()
else
Collect(Input)
end
end
end)
-- Mobile: Touch input
if UserInputService.TouchEnabled then
UserInputService.TouchTap:Connect(function(_, gameProcessedEvent)
if not gameProcessedEvent then
HandleClick()
print("ok")
end
end)
end
function AddOrRemoveSelectGui(WhatToDo, MODEL)
if MODEL then
if WhatToDo == "SELECT" then
if script.Values.CurrentSelectedPart.Value then
script.Values.CurrentSelectedPart.Value.Parent.ItemHoverGui:Destroy()
end
local HoverGui = script.ASSETS.ItemHoverGui:Clone()
HoverGui.Parent = MODEL
HoverGui.Itemname.Text = MODEL.Name
script.Values.CurrentSelectedPart.Value = MODEL.DROPPED_ITEM_PRIMARY
script.Values.LastSelectedPart.Value = MODEL
end
elseif WhatToDo == "CANCEL" then
if script.Values.CurrentSelectedPart.Value then
script.Values.CurrentSelectedPart.Value.Parent.ItemHoverGui:Destroy()
script.Values.CurrentSelectedPart.Value = nil
script.Values.LastSelectedPart.Value = nil
warn("destroyed hovergui")
end
end
end
function getPartUnderMouse(Object)
if Object.Parent:FindFirstChild("Pickable") and Object.Parent.Pickable.Value then
script.Server_Event.Value:FireServer("SELECT", Object.Parent)
AddOrRemoveSelectGui("SELECT", Object.Parent)
else
AddOrRemoveSelectGui("CANCEL")
end
end
function CheckTarget()
local Object = mouse.Target
local Root = Player.Character and Player.Character:FindFirstChild("HumanoidRootPart")
if Object and Root then
script.Values.MouseTarget.Value = Object
if (Root.Position - Object.Position).Magnitude <= script.Values.MaxSelectionDist.Value then
getPartUnderMouse(Object)
else
AddOrRemoveSelectGui("CANCEL")
end
end
end
UserInputService.InputChanged:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseMovement then
CheckTarget()
end
end)
its not reacting to mousemovement on mobile which means it doesnt update the target.value. how can i make this mobile compitable?