Help me please Tool.Equipped not firing

I do not understand why onEquip is not firing…
I Can see the tool moving from the players backpack onto the player. Problem is that onEquip won’t fire. It won’t even print(“EQ”)

The scripted worked perfectly fine yesterday but not today. I get no errors in studio.

Any ideas?

local Tool = script.Parent
local Handle = Tool:WaitForChild("Handle")
local FirePointObject = Handle:WaitForChild("GunFirePoint")

local Camera = game.Workspace.CurrentCamera
local Player = game.Players.LocalPlayer
local Humanoid = game.Players.LocalPlayer.CharacterAdded:Wait():WaitForChild("Humanoid")

local Mouse = Player:GetMouse()
--local MouseEvent = Tool:WaitForChild("MouseEvent")

local RemoteEvents = game.ReplicatedStorage:WaitForChild("RemoteEvents")
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")
--local Players = game:GetService("Players")

local showWeapon = false
Mouse.Icon = "http://www.roblox.com/asset?id=6115790362"

local function onEquip()
	print("EQ")
	showWeapon = true
	while showWeapon do
		viewModel = game.ReplicatedStorage:WaitForChild("viewModel"):Clone()
		weapon = game.ReplicatedStorage:WaitForChild("TX-110Model"):Clone()

		weapon.Parent = viewModel
		viewModel.Parent = Camera

		Camera.FieldOfView = 70
		print("ON")
		
		UserInputService.MouseIconEnabled = true

		local function updateArm(key)
			-- get shoulder we are rotating
			local shoulder = viewModel[key.."UpperArm"][key.."Shoulder"]
			-- calculate worldspace arm cframe from Right or Left part in the weapon model
			local cf = weapon[key].CFrame * CFrame.Angles(math.pi/2, 0, 0) * CFrame.new(0, 1.5, 0)
			-- update the C1 value needed to for the arm to be at cf (do this by rearranging the joint equality from before)
			shoulder.C1 = cf:inverse() * shoulder.Part0.CFrame * shoulder.C0
		end

		function onUpdate(dt)
			viewModel.Head.CFrame = Camera.CFrame
			updateArm("Right")
			updateArm("Left")

		end

		local joint = Instance.new("Motor6D")
		joint.C0 = CFrame.new(1.3, -1.5, -.8) -- what I found fit best
		joint.Part0 = viewModel.Head
		joint.Part1 = weapon.Handle
		joint.Parent = viewModel.Head

			
		moveWeapon = RunService.RenderStepped:Connect(onUpdate)

		while (true) do
			wait(0.1)
			RemoteEvents.tiltAt:FireServer(math.asin(Camera.CFrame.LookVector.y))
		end
	end
end

local function onUnequip()
	showWeapon = false
	UserInputService.MouseIconEnabled = false
	viewModel:Destroy()
	weapon:Destroy()
	moveWeapon:Disconnect(onUpdate)	
end

local function onActivate()
	--MouseEvent:FireServer(Mouse.Hit.Position)
end

local function onDeactivate()
end

local function onDied()
	showWeapon = false
	UserInputService.MouseIconEnabled = false
	viewModel:Destroy()
	weapon:Destroy()
	moveWeapon:Disconnect(onUpdate)
end

Tool.Equipped:Connect(onEquip)
Tool.Unequipped:Connect(onUnequip)
Tool.Activated:Connect(onActivate)
Tool.Deactivated:Connect(onDeactivate)
--Humanoid.Died:Connect(onDied)

Does it show any error? Is this in a local script?

This is a local script, there is no error and the tool has a Handle.

I see that you have the print function at the first line of the scope of OnEquip function, did it print out the EQ?

No it doesn’t that’s why I’m so puzzled…

I know a way to detect which code line starts to error, but it might be a bit complicated. Do you know what’s print debug?

Not familiar with that no. Got a Dev link to read up on?

No, but it’s a way to find out which code line is erroring. Let’s say you wanna see if this code line works:

local result = —random stuffs here.

You’ll might be this won’t work, so you will put like print functions between this code line to check which code line is not working. For example:

print(“is”)
local result = —random stuffs here.
print(“sd”)

So let’s say if the output prints is, and it doesn’t print sd, we can say that code line has an error. However if it’s sd and NOT is, then there’s something wrong with the code lines before this one. If both prints, then that code line is working. I hope you understand.

Try to use it at code lines that you’re unsure that it will error or not.

For some reason using the Lau debugger the script stops on its own on line 7.

local Humanoid = game.Players.LocalPlayer.CharacterAdded:Wait():WaitForChild("Humanoid")

No idea what is causing that…

Did you use the print debug???

I used the Lua debug stepper…

This is what happens

print("1")
local humanoid = Player.CharacterAdded:Wait():WaitForChild("Humanoid")
print("2")

Only the 1 prints…

Try this:

local char = player.Character
repeat wait() until char
local humanoid = char.Humanoid

I fixed it.

Calling Player.CharacterAdded:Wait() in a local script will wait forever

Changed to

local humanoid = Player.Character:WaitForChild("Humanoid")

Now it all works.

1 Like

I can’t help, but you fixed it so congrats.