No errors are recieved and the item is not cloned to the player backpack.
Pickup item script:
local PickupItem = ReplicatedStorage:WaitForChild("PickupItem")
local maxPickupDistance = 30
PickupItem.OnServerEvent:Connect(function(player, item)
local distanceFromItem = player:DistanceFromCharacter(item.Handle.Position)
if distanceFromItem < maxPickupDistance then
local toolclone = item:Clone()
toolclone:Clone()
toolclone.Handle.Anchored = false
toolclone = player.Backpack
end
end)
Script firing event:
local PickupItem = ReplicatedStorage:WaitForChild("PickupItem")
local UIS = game:GetService("UserInputService")
local pickupKey = "E"
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local playerGui = player:WaitForChild("PlayerGui")
local ToolPickupGUI = playerGui:WaitForChild("ToolPickupGUI")
UIS.InputChanged:Connect(function()
if mouse.Target then
if mouse.Target.Parent:IsA("Tool") then
ToolPickupGUI.Enabled = true
playerGui.ToolPickupGUI.Adornee = mouse.Target
else
ToolPickupGUI.Enabled = false
playerGui.ToolPickupGUI.Adornee = nil
end
end
end)
UIS.InputEnded:Connect(function(input)
if input.KeyCode == Enum.KeyCode[pickupKey] then
if mouse.Target then
if mouse.Target.Parent:IsA("Tool") then
local item = mouse.Target.Parent
if item then
PickupItem:FireServer(item)
end
end
end
end
end)
the tool isnt cloning as the RemoteEvent is never fired. Put PickupItem:FireServer(<Define The Tool To Clone Here>) on a line where you want the client to tell the server to give the localplayer said tool
Not sure if this is the issue but why are you cloneing it once then again? Makes no sense when you could just do the things to toolclone not cloneing it twice.
Also just so you know players can walk on a tool on the ground to pick it up. I would recommend having all tools in lets say ServerStorage in a folder called Tools and having the visible tools on the group just models of the tools and running your script from there
if mouse.Target.Parent:IsA("Tool") then
to if mouse.Target.Parent:IsA("Model")
and please do send any errors that show up in output
But you don’t clone to the workspace in these scripts do u? Not sure why you get that error but I belive that is why it will not clone to the backack.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local PickupItem = ReplicatedStorage:WaitForChild("PickupItem")
local maxPickupDistance = 30
PickupItem.OnServerEvent:Connect(function(player, item)
local distanceFromItem = player:DistanceFromCharacter(item.Handle.Position)
if distanceFromItem < maxPickupDistance then
local toolclone = item:Clone()
toolclone.Handle.Anchored = false
toolclone = player.Backpack
end
end)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local PickupItem = ReplicatedStorage:WaitForChild("PickupItem")
local UIS = game:GetService("UserInputService")
local pickupKey = "E"
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local playerGui = player:WaitForChild("PlayerGui")
local ToolPickupGUI = playerGui:WaitForChild("ToolPickupGUI")
UIS.InputChanged:Connect(function()
if mouse.Target then
if mouse.Target.Parent:IsA("Tool") then
ToolPickupGUI.Enabled = true
playerGui.ToolPickupGUI.Adornee = mouse.Target
else
ToolPickupGUI.Enabled = false
playerGui.ToolPickupGUI.Adornee = nil
end
end
end)
UIS.InputEnded:Connect(function(input)
if input.KeyCode == Enum.KeyCode[pickupKey] then
if mouse.Target then
if mouse.Target.Parent:IsA("Tool") then
local item = mouse.Target.Parent
if item then
PickupItem:FireServer(item)
end
end
end
end
end)