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

my tool script is giving more tools than i want? FIXED

Asked by 3 years ago
Edited 3 years ago

please help me

player = game.Players.LocalPlayer
mouse = player:GetMouse()
itemnear = nil


while true do
pcall(function()
    local modelRoots = game.Workspace.Items:GetChildren()
    for i = 1,#modelRoots do
local playerRoot = script.Parent.HumanoidRootPart
local distance = (playerRoot.Position - modelRoots[i].Position).Magnitude 
local radius = 10
if(distance <= radius) then
                print("Your close to "..modelRoots[i].Name)
                itemnear = modelRoots[i]
            else
    itemnear = nil
    end
    end
    end)
    pcall(function()
    mouse.KeyDown:Connect(function(key)
        if key == "f" then
            if itemnear then
                print("Picked Up "..itemnear.Name)
                    game.ReplicatedStorage.ItemSystem.PickUpEvent:FireServer(itemnear)
                    itemnear:Destroy()

            end
        end
        end)
        end)
    wait(0.5)
end

also the server script

game.ReplicatedStorage.ItemSystem.PickUpEvent.OnServerEvent:Connect(function(plr,item)
    local clone = game.ReplicatedStorage.ItemSystem:FindFirstChild(item.Name):Clone()
    clone.Parent = plr.Character
    return
end)

1 answer

Log in to vote
0
Answered by 3 years ago

I am not that smart but maybe add return at the end?

0
it didn't work Everett2010 15 — 3y
0
I fixed it Everett2010 15 — 3y
Ad

Answer this question