ItemGive script doesn't work

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

On where did you put it? On a block or something else?

1 Like

image

Try to use the Script, if it doesn’t work just use the LocalScript thing then.

What do you mean with try to the Script?

I use the Local Script to fire the Remote Events and the ServerScript to handle them, lol.

Are you trying to click on yourself?

You using click detector on it btw?

No, I’m trying to click a player so he receives the item that I have currently equipped.

I can’t use a ClickDetector inside of every player, lol.

I want it so that if I click a player, he receives the Item that is currently equipped. I can just do mouse.Target.

Put the click detector and then try again.

I think you didn’t understand what I’m trying to do. I want it so that if you equipped an item and click another player, he receives your item and your item gets removed. I can’t put a ClickDetector inside of a player.

Why not? 303030303033030303030330

Look into Mouse.Hit function on roblox dev hub