How do you make a script that finds the player holding the tool?

Sorry to repost, but my last post has zero responses (it’s been 5 hours), and I was hoping to re-try.

I was very happy with my previous script, but it only worked with a LocalScript and when it killed a player it would only be cilent-sided. Anyway, here’s my problem: I’m trying to make a tool.touched event so it would make the variables , how ever, the variables don’t carry on to another function, and when I try making it out of the tool.touched event, it thinks that Workspace is the player.
Script:

-- Ball
local Ball = script.Parent.Default_Ball
local Tool = script.Parent
-- Animation
local Animation = Instance.new("Animation")
Animation.AnimationId = "rbxassetid://13962251515"
-- Settings
local debounce = false -- Cooldown

Tool.Touched:Connect(function(Grabbed)
	local character = Tool.Parent
	local Player = game:GetService("Players"):GetPlayerFromCharacter(character)
	local Character = Player.Character
	local Humanoid = Character.Humanoid
	Animation.Parent = Humanoid.Animator
end)

Tool.Activated:Connect(function(activated)
	local HitAnimPlay = Humanoid:LoadAnimation(Animation)
	if not debounce then
		debounce = true
		HitAnimPlay:Play()
		wait(1.5)
		debounce = false
	end
end)

Ball.Touched:Connect(function(hit)
	local enemyplayer = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
	if not debounce then
		if enemyplayer then
			enemyplayer.Character.Humanoid.Health = - 10
			debounce = true
			wait(1.5)
			debounce = false
		end
	end
end)

where is your script located is it in the tool?

Yeah, the script is inside of the tool

is the tool inside of the player?

maybe it is in the workspace and you set up variables when it is in workspace

so the script thinks that workspace is player, you should set up player variable when you are sure the tool is inside the player’s backpack

I could try putting it in ReplicatedStorage

But how would I go about that?

try this → print(tool.Parent)
then
print(player.Parent)

like that you can check for sure who is the player variable’s parent.

where is the tool located? is it in starterPack, workspace, folder?

When a tool is equipped / held, the tool’s parent is the player’s Character. When the tool is not equipped, the tool’s parent is the player’s Backpack.

2 Likes