Help with soccer ball script

So im trying to make a soccer game and make it so if the ball touches the player the ball follows the player and if the ball touches a part other then parts named “Floor” and the humanoid the player cant pickup the ball for 1 second and the ball rolls, But the problem with this script is that the ball does not follow the player. Everything else works, here’s my script.

local players = game:GetService("Players")
local ball = script.Parent
local currentPlayer = nil

ball.Touched:Connect(function(hit)
	local player = game.Players:GetPlayerFromCharacter(hit.Parent)
	if player and player ~= currentPlayer and hit.Parent:FindFirstChild("Humanoid") then
		currentPlayer = player
		ball.Anchored = false
		ball.CanCollide = true
		ball.Velocity = Vector3.new(0,0,0)
		ball.Position = currentPlayer.Character.HumanoidRootPart.Position + Vector3.new(0,0,1)
		wait(1)
		ball.CanCollide = false
		ball.Anchored = true
	end
end)

1 Like

I need help. Please hurry, plus I need activity so yeah

This touch event will only fire once because you set currentPlayer to prevent a re-entry condition. This also means that position of the ball will only be set once because it is contained in the same code you are preventing re-entry into.

3 Likes

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