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

My ItemGiver script doesn't work. It doesn't print Yes4 and Yes5?

--Local Script:
local player = game.Players.LocalPlayer
local Tool = script.Parent
local mouse = player:GetMouse()
local Character = player.CharacterAdded:Wait()
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ItemGive = ReplicatedStorage:FindFirstChild("ItemGive")
local isEquipped = false

Tool.Equipped:Connect(function()
	isEquipped = true
end)

Tool.Unequipped:Connect(function()
	isEquipped = false
end)


mouse.Button2Down:Connect(function()
	
	print("Yes1") --Gets printed
	
	if isEquipped == true then
		
		print("Yes2") --Gets printed
		
		local MouseTarget = mouse.Target
		
		if MouseTarget ~= nil then
			
			print("Yes3") --Gets printed
			
			if MouseTarget.Parent:FindFirstChild("Humanoid") then
				
				print("Yes4") --Doesn't get printed
				
				local TargetPlayer = game.Players:GetPlayerFromCharacter(MouseTarget.Parent)
				
				if TargetPlayer ~= game.Players:GetPlayerFromCharacter(Character) then
					
					print("Yes5") --Doesn't get printed
					
					local TargetPlayerBackpack = TargetPlayer.Backpack
					
					ItemGive:FireServer(TargetPlayerBackpack, Tool)
					
					print("Success!") --Doesn't get printed

				end		
				
			end
			end
	end
end)


--ServerScript:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ItemGive = ReplicatedStorage:FindFirstChild("ItemGive")
local ToolToGetCloned = ReplicatedStorage:FindFirstChild("Tool")


ItemGive.OnServerEvent:Connect(function(plr, TargetPlayerBackpack)
	local ToolClone = ToolToGetCloned:Clone()
	ToolClone.Parent = TargetPlayerBackpack
	
end)

1 comment

0

that means that you have to activate the tool at a character, I think

1 answer

make

MouseTarget.Parent:FindFirstChild("Humanoid")

this

MouseTarget.Parent:FindFirstChildOfClass("Humanoid")or MouseTarget.Parent.Parent:FindFirstChildOfClass("Humanoid")

and have it print out the target

1 comment

0

FindFirstChildWhichIsA has a recursive boolean. Shouldn't you stick with MouseTarget.Parent.Parent and that function?

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