Hi there, so my game(R15 characters) involves a ball and I'm trying to create a tool that enables players to pick it up. So in the coding below I'm trying to make it so when you press 'R', it plays an animation I made where the player bends down, and then during that animation if their right hand touches the ball then the ball attaches to the hand, resulting in the player picking the ball up. (Extra Info: The ball is a part in the workspace called 'Ball1'. The value called 'Ball' is a child within the Tool.)
Any help would be greatly appreciated as this is frustrating me!
local tool = script.Parent
local Equipped = false
local debounce = false
UserInputService = game:GetService("UserInputService")
tool.Activated:Connect(function()
Equipped = true
end)
tool.Equipped:Connect(function()
Equipped = true
end)
tool.Unequipped:Connect(function()
Equipped = false
end)
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.Locked == true or hit.Anchored == true then return end
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)

1 comment
you have to make it come out of the closet. what i mean is if your ball is a part and it's attracted to the same part, but it isn't open about it. it won't work, causing denial and would want to prove itself to other parts. it would constently say that he is not attracted to the same part, and show some pictures of naked parts and be like, "oo ya, im into that cute cylander part and not spheres"