I was following a tutorial but I changed some things so it is usable on mobile, so then players can click the wood to to pick it up, it works perfectly exept that it can get picked up with any keycode instead of just the keycode F.
local UIS = game:GetService("UserInputService") local ReplicatedStorage = game:GetService("ReplicatedStorage") local PickupItem = ReplicatedStorage:WaitForChild("Remotes"):WaitForChild("PickupItem") local pickupKey = "F" local player = game.Players.LocalPlayer local mouse = player:GetMouse() local item = mouse.Target local distanceFromItem = nil local PlayerGui = player:WaitForChild("PlayerGui") local PickupInfoGui = PlayerGui:WaitForChild("PickupInfoGui") UIS.InputBegan:Connect(function(input) if mouse.Target and input.KeyCode == Enum.KeyCode.F then if mouse.Target:FindFirstChild("Pickable") then local item = mouse.Target PickupInfoGui.Adornee = item PickupInfoGui.ObjectName.Text = item.Name PickupInfoGui.Enabled = true else PickupInfoGui.Adornee = nil PickupInfoGui.Enabled = false end end end) UIS.InputEnded:Connect(function(input) if mouse.Target then if mouse.Target:FindFirstChild("Pickable") then item = mouse.Target if item then distanceFromItem = player:DistanceFromCharacter(item.Position) if item.Touched then --if item clicked, I feel like it is here. PickupItem:FireServer(item) elseif input.KeyCode == Enum.KeyCode.F then --if player type F PickupItem:FireServer(item) end end end end end)
UIS.InputChanged:Connect(function(input) if mouse.Target then if mouse.Target:FindFirstChild("Pickable") then local item = mouse.Target PickupInfoGui.Adornee = item PickupInfoGui.ObjectName.Text = item.Name PickupInfoGui.Enabled = true else PickupInfoGui.Adornee = nil PickupInfoGui.Enabled = false end end end)
You have a variable, pickupkey but you never use it. It's likely you didn't finish the tutorial or the tutorial was half-assed.
Either way, specify which input you want like this:
UIS.InputBegan:Connect(function(input) if mouse.Target and input.KeyCode == Enum.KeyCode.F then if mouse.Target:FindFirstChild("Pickable") then local item = mouse.Target PickupInfoGui.Adornee = item PickupInfoGui.ObjectName.Text = item.Name PickupInfoGui.Enabled = true else PickupInfoGui.Adornee = nil PickupInfoGui.Enabled = false end end end)
Same goes for InputEnded, understand what I did visually and replicate it. Also, remove line 36
Side note: I also changed it to InputBegan vs InputChanged there is a minor difference that you can search up but it shouldn't impact you very hard.
Larger edit:
UIS.InputEnded:Connect(function(input) if mouse.Target then if mouse.Target:FindFirstChild("Pickable") then item = mouse.Target if item then distanceFromItem = player:DistanceFromCharacter(item.Position) if item.Touched then --if item clicked, I feel like it is here. if input.KeyCode == Enum.KeyCode.F then PickupItem:FireServer(item) end end end end end)
All the codes you need to make what you want will be included here.
Basic proximity prompt
workspace.Part.ProximityPrompt.Triggered:Connect(function(player) print("The user interacted with me!") end)
Checking which device a player is in (i think this will work... I found this on the internet
local UIS = game:GetService("UserInputService") local GuiService = game:GetService("GuiService") if UIS.TouchEnabled and not UIS.KeyboardEnabled and not UIS.MouseEnabled and not UIS.GamepadEnabled and not GuiService:IsTenFootInterface() then -- mobile device else --pc end