Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

gives me 2 wood instead of 1 wood, I need it to be 1 wood?

Asked by
xxaxxaz 42
3 years ago
Edited 3 years ago

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.

01local UIS = game:GetService("UserInputService")
02local ReplicatedStorage = game:GetService("ReplicatedStorage")
03local PickupItem = ReplicatedStorage:WaitForChild("Remotes"):WaitForChild("PickupItem")
04local pickupKey = "F"
05 
06local player = game.Players.LocalPlayer
07local mouse = player:GetMouse()
08 
09local PlayerGui = player:WaitForChild("PlayerGui")
10local PickupInfoGui = PlayerGui:WaitForChild("PickupInfoGui")
11 
12UIS.InputChanged:Connect(function(input)
13    if mouse.Target then
14        if mouse.Target:FindFirstChild("Pickable") then
15            local item = mouse.Target
View all 57 lines...
0
sorry about the grammer for the title, I had to shorten it so it was under 100 characters long. xxaxxaz 42 — 3y
0
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. Zeppelin0330 38 — 3y
0
yes but one of them say a if command in it to see if it was clicked. xxaxxaz 42 — 3y

2 answers

Log in to vote
1
Answered by 3 years ago

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

Ad
Log in to vote
0
Answered by 3 years ago

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:

01UIS.InputEnded:Connect(function(input)
02        if input.KeyCode == Enum.KeyCode.F or input.UserInputType = Enum.UserInputType.MouseButton1 then
03            if mouse.Target then
04            if mouse.Target:FindFirstChild("Pickable") then
05                    local item = mouse.Target
06                    if item then
07                        local distanceFromItem = player:DistanceFromCharacter(item.Position)
08                 if distanceFromItem < 30 then
09                        PickupItem:FireServer(item)
10 
11                        end
12                    end
13                end
14            end
15        end
16    end)
0
they are not indinticle xxaxxaz 42 — 3y
0
but thx for trying xxaxxaz 42 — 3y

Answer this question