Why does this not work?
--//Local Script//--
local Tool = script.Parent
local Handle = Tool.Handle
local player = game.Players.LocalPlayer
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local mouse = player:GetMouse()
local isEquipped = false
local HumCheck = ReplicatedStorage.HumCheck
local GiveItemToPlayer = ReplicatedStorage.GiveItemToPlayer
Tool.Equipped:Connect(function()
isEquipped = true
end)
Tool.Unequipped:Connect(function()
isEquipped = false
end)
mouse.Button2Down:Connect(function()
if isEquipped then
local MouseTarget = mouse.Target
local isHumanoidandBackpackofTarget = HumCheck:InvokeServer(MouseTarget) --Error: Parent is nil
print("Yes1") --Gets printed
if isHumanoidandBackpackofTarget then
print("Yes2") --Got printed once, nothing happened
GiveItemToPlayer:FireServer(isHumanoidandBackpackofTarget)
print("Yes3") --Got printed once, nothing happened
end
end
end)
--//Server Script//--
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local HumCheck = ReplicatedStorage.HumCheck
local GiveItemToPlr = ReplicatedStorage.GiveItemToPlayer
local function HumanoidCheck(plr, MouseTarget)
if MouseTarget.Parent:FindFirstChild("Humanoid") then
local MouseTargetChar = MouseTarget.Parent
return MouseTargetChar
else
return false
end
end
HumCheck.OnServerInvoke = HumanoidCheck
local function GiveItemToPlayer(plr, TargetBackpack)
local PlrBackPack = plr.Backpack
local ClonedTool = PlrBackPack.Tool:Clone()
PlrBackPack.Tool:Destroy()
ClonedTool.Parent = TargetBackpack
end
GiveItemToPlr.OnServerInvoke = GiveItemToPlayer