GetPlayerFromCharacter is a function of the player service (game:GetService(“Players”)), you input the player’s character as the first argument and if it’s a player’s character it returns the player instance else nil.
so that’s one issue out of the way let’s address the next one, you’re checking if hit.Parent has a child named “Humanoid” which is completely fine but you’re assigning the value of the variable “player” before that and you don’t even use that variable outside of that if statement so move that in after you fix it.
Another thing that’s small but better “safe than sorry”, instead of using a wait(2) as a debounce just set 1 variable named “lastUsed” and it’s value will be tick(), each time .Touched is fired check if tick() - lastUsed is lower than 2, if so then return (aka don’t do anything) else run the code (that way it’s more precise and I guess better in general).
EDIT : I didn’t see the second screenshot so I’ll address the issues in it too~
The GetPlayerFromCharacter issue, already talked about so moving on.
WaitForChild - The way you’re using WaitForChild is horrible, you’re waiting for an object that’s named “Tool” under the character (which wouldn’t be the case if the player wasn’t holding their tool), same thing with the line below it so consider doing the following :
Instead of using WaitForChild use the function “FindFirstChildOfClass”, iirc the player can only hold one tool at a time, if you’re checking if they’re holding a tool then FindFirstChildOfClass would be the best choice to use, the first argument is the class name which is “Tool” in your use case.
Another thing I wanted to point out is your characterTool and backpackTool variables, you can make those into 1 variable using “or”.
local foundTool = player.Character and player.Character:FindFirstChildOfClass("Tool") or player.Backpack:FindFirstChildOfClass("Tool")
if foundTool then
Though please do keep in mind that FindFirstChildOfClass searches for the first object with the inputted class name not “name”, so if you’re specifically searching for “Tool” then use FindFirstChild.