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)

3 comments
sorry about the grammer for the title, I had to shorten it so it was under 100 characters long.
You seem to be firing the even twice UIS.input ended event twice as line 27-42 is fired and then likes 43-57 fire and since the checks are the same its gonna pass and thus the collecting event is fired twice so your collection doubles.
yes but one of them say a if command in it to see if it was clicked.