Local Script detect player tool problem

Hi I’m currently making a Local Script works only if a tool is being used.
The Local Script works perfectly on detecting if a player is holding the tool or not, the problem is that when I’m not using the tool and pressing the Key then use the tool again it suddenly activates.

Here is the script i was working on:

				if key == "g" then
					if game.Workspace[Player.Name]:WaitForChild("Aircraft") then
						if CurrentGear == "Down" then
							CurrentGear = "Up"
							LandingGearUpSound = true
							LandingGearEvent = script.LandingGearValue.Value.LandingGearEvent
							LandingGearEvent:FireServer(LandingGearUpSound)
							print("Gear Up")
						elseif CurrentGear == "Up" then
							CurrentGear = "Down"
							LandingGearDownSound = false
							LandingGearEvent = script.LandingGearValue.Value.LandingGearEvent
							LandingGearEvent:FireServer(LandingGearDownSound)
							print("Gear Down")

I can provide F9 Logs video if needed.

It’s because you’re using :WaitForChild, which will wait until that child exists before moving forward. Use :FindFirstChild. You can also use Player.Character, instead of workspace[Player.Name].

Code:

if key == "g" then
					if Player.Character:FindFirstChild("Aircraft") then
						if CurrentGear == "Down" then
							CurrentGear = "Up"
							LandingGearUpSound = true
							LandingGearEvent = script.LandingGearValue.Value.LandingGearEvent
							LandingGearEvent:FireServer(LandingGearUpSound)
							print("Gear Up")
						elseif CurrentGear == "Up" then
							CurrentGear = "Down"
							LandingGearDownSound = false
							LandingGearEvent = script.LandingGearValue.Value.LandingGearEvent
							LandingGearEvent:FireServer(LandingGearDownSound)
							print("Gear Down")

If it doesn’t work, please send a video and F9 logs.

The Local Script worked! Thanks!!!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.