Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

This discussion is preserved as it was. New answers, comments, and votes are closed.