#two ball under the player
15 messages · Page 1 of 1 (latest)
`local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local CreateBallEvent = ReplicatedStorage:WaitForChild("CreateBall")
local function createBallForPlayer(player)
local character = player.Character or player.CharacterAdded:Wait()
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
-- Vérifier si une balle est déjà attachée au joueur
if humanoidRootPart:FindFirstChild("Ball") then
return -- Ne pas créer de nouvelle balle si une est déjà attachée
end
-- Créer une nouvelle balle
local ball = Instance.new("Part")
ball.Name = "Ball"
ball.Size = Vector3.new(5, 5, 5) -- Taille de la balle
ball.Shape = Enum.PartType.Ball
ball.Material = Enum.Material.SmoothPlastic
ball.BrickColor = BrickColor.new("Bright blue")
ball.Anchored = false
ball.CanCollide = true
ball.Parent = game.Workspace -- Placer la balle dans l'espace de travail
-- Positionner la balle sous le joueur
ball.Position = humanoidRootPart.Position - Vector3.new(0, 3.5, 0) -- Ajuster pour placer sous le joueur
-- Fixer la balle sous le joueur
local attachment0 = Instance.new("Attachment", humanoidRootPart)
attachment0.Position = Vector3.new(0, -3.5, 0) -- Positionner l'attache sous le joueur
local attachment1 = Instance.new("Attachment", ball)
local ballSocketConstraint = Instance.new("BallSocketConstraint")
ballSocketConstraint.Attachment0 = attachment0
ballSocketConstraint.Attachment1 = attachment1
ballSocketConstraint.Parent = ball
-- Ajouter un BodyVelocity pour gérer le mouvement
local bodyVelocity = Instance.new("BodyVelocity")
bodyVelocity.Velocity = Vector3.new(0, 0, 0)
bodyVelocity.MaxForce = Vector3.new(1e6, 0, 1e6)
bodyVelocity.Parent = ball`
` -- Ajouter un BodyGyro pour stabiliser la balle
local bodyGyro = Instance.new("BodyGyro")
bodyGyro.MaxTorque = Vector3.new(1e6, 1e6, 1e6)
bodyGyro.P = 3000
bodyGyro.D = 500
bodyGyro.Parent = ball
-- Supprimer la balle si le joueur meurt
local function onPlayerDied()
if ball then
ball:Destroy()
end
end
character:WaitForChild("Humanoid").Died:Connect(onPlayerDied)
end
CreateBallEvent.OnServerEvent:Connect(function(player)
createBallForPlayer(player)
end)
Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
createBallForPlayer(player)
end)
end)
-- Pour les joueurs déjà présents (lors de l'activation du script)
for _, player in pairs(Players:GetPlayers()) do
if player.Character then
createBallForPlayer(player)
end
end`
If HumanoidRootPart:FindFirstChild("Ball") does not work properly because ball is parented to workspace
So what should I do
** You are now Level 1! **
You should parent it to the humanoidrootpart
And how does it work 😭 what should I type
That's my first game tbh
Did you not type this code yourself
If not just change the ball.Parent line to ball.Parent = HumanoidRootPart