I was following a tutorial with a bit of changes, but when I pressed F it would five me double the amount of wood, and when I press anything else then F or click the wood I get the normal amount. I just want it to give me the normal amount. btw there is not a error.
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 PlayerGui = player:WaitForChild("PlayerGui") local PickupInfoGui = PlayerGui:WaitForChild("PickupInfoGui") 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) --I think the problem is these 2 if statements. UIS.InputEnded:Connect(function(input) --this one has a enum keycode for F if input.KeyCode == Enum.KeyCode.F then if mouse.Target then if mouse.Target:FindFirstChild("Pickable") then local item = mouse.Target if item then local distanceFromItem = player:DistanceFromCharacter(item.Position) if distanceFromItem < 30 then PickupItem:FireServer(item) end end end end end end) UIS.InputEnded:Connect(function()--this one has a if item.Touched if mouse.Target then if mouse.Target:FindFirstChild("Pickable") then local item = mouse.Target if item then if item.Touched then local DistanceFromItem = player:DistanceFromCharacter(item.Position) if DistanceFromItem < 30 then PickupItem:FireServer(item) end end end end end end)
Try adding an F button on mobile so then on the screen for mobile players, instead of having to click it they can just click the extra F
Lines 27- 42 and 43-57 are fired at the same time and so your checks in both pass since they are identical you would have both events fire which would as a result double the collection. I suggest you to remove lines 43-57 and change your lines 27 -42 to:
UIS.InputEnded:Connect(function(input) if input.KeyCode == Enum.KeyCode.F or input.UserInputType = Enum.UserInputType.MouseButton1 then if mouse.Target then if mouse.Target:FindFirstChild("Pickable") then local item = mouse.Target if item then local distanceFromItem = player:DistanceFromCharacter(item.Position) if distanceFromItem < 30 then PickupItem:FireServer(item) end end end end end end)