How to make the script find the player character?

Hello! Am trying to make this script check if the player took his tool out. How would I get the game check if the player is holding it? This is a script and not localscript!

while wait(1) do
	if script.Parent.Front.SurfaceLight.Enabled == true then
		if script.Parent.FlashlightScript.FlashlightBattery.Value > 0 then
			script.Parent.FlashlightScript.FlashlightBattery.Value -= 1
		else
			script.Parent.Front:WaitForChild("SurfaceLight").Enabled = false
			script.Parent.Light:WaitForChild("Light").Enabled = false
			script.Parent.Light:WaitForChild("Shadow").Enabled = false
		end
	end
		if script.Parent.Parent == player.Character then
			script.Parent.Front:WaitForChild("SurfaceLight").Enabled = false
			script.Parent.Light:WaitForChild("Light").Enabled = false
			script.Parent.Light:WaitForChild("Shadow").Enabled = false
		else
			script.Parent.Front:WaitForChild("SurfaceLight").Enabled = true
			script.Parent.Light:WaitForChild("Light").Enabled = true
			script.Parent.Light:WaitForChild("Shadow").Enabled = true
	end
end

You can use ToolInstance.Equipped:Connect() to detect if a player equips a tool.
From there, finding the character would just be ToolInstance.Parent.

I think thats right anyway - I’ve not done much scripting for a while.

Small example for if the script is parented to the Tool:

local Tool = script.Parent

Tool.Equipped:Connect(function()
    print("Player",Tool.Parent.Name,"equipped the tool")
end)

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