How would it be possible to carry along the 'locals' to an event?

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)
2 Likes

Use

tool.Equipped

and not

tool.Touched

1 Like

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