Hi there, so in my game (R15) I’m trying to make it so if a player presses ‘R’ with a tool equipped, it plays an animation of the player bending down, and during this if they player’s hand comes into contact with ‘Ball1’ (A part within the workspace) then the ball is attached to their hand. Here’s the part of the script for the USI and touched function, in test when I press R I get an ‘attempt to call a nil value’ error on the ‘Attach(ball)’ line of code.
UserInputService.InputBegan:Connect(function(Input, gameProccesedEvent)
if gameProccesedEvent then return end
if Input.KeyCode == Enum.KeyCode.R and Equipped == true then
if not debounce then
debounce = true
local player = game.Players.LocalPlayer
local Animation = Instance.new("Animation", player.Character)
Animation.AnimationId = "rbxassetid://5170994435"
local AnimationLoaded = player.Character.Humanoid:LoadAnimation(Animation)
AnimationLoaded:Play()
wait(0.5)
RH = game.Players.LocalPlayer.Character.RightHand
RH.Touched:Connect(function(hit)
if hit.Name == "Ball1" then
script.Parent.Ball.Value = 1
RH = game.Players.LocalPlayer.Character.RightHand
local ball = hit
if (RH.Position - ball.Position).magnitude then
Attach(ball)
debounce = false
end
end
end)
end
end
end)
I’m not sure what else to do as I’ve tried everything to my knowledge, so any thoughts or help would be really appreciated! Thank you