0

why can I pick up the wood with any keycode when I just want it to be the keycode F?

xxaxxaz 38
4 days ago
Edited 4 days ago

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.ObjectName.Text = item.Name
PickupInfoGui.Enabled = true
else
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)


0
Why are you not useing a proximity promt??? Xyternal 145 — 4d
0
because that is not what I need but I will try to make one xxaxxaz 38 — 4d

1
Edited 4 days ago
UIS.InputChanged:Connect(function(input)
if mouse.Target then
if mouse.Target:FindFirstChild("Pickable") then
local item = mouse.Target
PickupInfoGui.ObjectName.Text = item.Name
PickupInfoGui.Enabled = true
else
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.ObjectName.Text = item.Name
PickupInfoGui.Enabled = true
else
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)


0
I did finish the tutorial but I changed the [inputkey] to F just to make sure that was not the problem xxaxxaz 38 — 4d
1
Xyternal 145
4 days ago

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

0
thx xxaxxaz 38 — 4d
0
does not work error: Players.xxaxxaz.PlayerScripts.PickupManager:9: attempt to index nil with 'Position' - Client - PickupManager:9 xxaxxaz 38 — 4d
0
I think it is because it does not auto clone to all the blocks that need it. xxaxxaz 38 — 4d
0
I made a succesful auto clone and it still does not work xxaxxaz 38 — 4d
0
hmm Xyternal 145 — 4d