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)

2 comments
Why are you not useing a proximity promt???
because that is not what I need but I will try to make one