How can I find what the players characters right hand touched

Im making a feature that would let you slap a model and make it produce double money. It will do this by duplicating a script and enabling it before the script eventually deletes itself and you have to do it again. My issue is I can find what the players touching. Any help would be great.

Code and errors
local script inside starter character scripts

errors
image

Did you ever parent the animation?

No, I dont think the animation has anything to do with it. The animation plays and while that plays the script checks what the hand touches.

That can’t be right, the error means that the animation is not in the game, thus why you need to parent it.

I dont have that error unless I check for what the hand touched

sup, try this

local function onTouch (hit)
   print(hit.Name)
end

character.RightHand.Touched:Connect(onTouch)
1 Like

also if you want to know as to why it didn’t print the instance, it’s because of the fact that .Touched is an event and not an index.

if it worked consider marking it as the solution so that others will be able to see the answer if they have a similar problem

Yeah it worked! You know what I can do to make it only do that while the smack is playing? Like tell it to stop. It still prints even after the smack.

Yeah, here’s the script:

local Players = game:GetService("Players")

local player = Players.LocalPlayer
local character = player.Character
if not character or not character.Parent then
   character = player.CharacterAdded:Wait()
end
local humanoid = character:WaitForChild("Humanoid")
local Animator = humanoid:WaitForChild("Animator")
local SLAP = Instance.new("Animation")
SLAP.AnimationId = "rbxassetid://9231471239"

local SAT = Animator:LoadAnimation(SLAP)

local function onTouch(hit)
   print(hit.Name) -- do whatever u want here
end

local connection

local function AnimPlay(player)
   SAT:Play()
   humanoid.WalkSpeed = 0
   connection = character.RightHand.Touched:Connect(onTouch) -- assigns the variable to the event
   wait(1)
   humanoid.WalkSpeed = 18
   connection:Disconnect() -- stops the event from running
end
1 Like