Hello everyone!
I’m doing a tool system that places a item on your backpack when you click a part,here’s the script!
local itemHandler = script.Parent
local itemsFinder = game.ServerStorage.Items
local Players = game:GetService(“Players”)
function getItem()
if itemsFinder:FindFirstChild(itemHandler.Name) then
print(“This is working!”)
local player = Players.LocalPlayer
if player then
local clonedItem = itemsFinder:FindFirstChild(itemHandler.Name):Clone()
clonedItem.Parent = player.Backpack
end
LocalPlayer can not be used inside of server scripts. It will return nil. Instead, for the function, add a parameter called “player” and it should work. Like this:
function getitem(player)
end
clickdetector.MouseClick:Connect(getitem)
You know you can get the player that clicked the part right?
Try this
local itemHandler = script.Parent
local itemsFinder = game.ServerStorage.Items
local Players = game:GetService(“Players”)
function getItem(plr)
if itemsFinder:FindFirstChild(itemHandler.Name) then
print(“This is working!”)
if plr then
local clonedItem = itemsFinder:FindFirstChild(itemHandler.Name):Clone()
clonedItem.Parent = plr.Backpack
end
else
print(“No”)
end
end
itemHandler.ClickDetector.MouseClick:Connect(getItem)