Touch Football Teleport To Ball Script
Touch Football Teleport To Ball Script
-- Properties
ScreenGui.Name = "TeleportBallGui"
ScreenGui.Parent = game.Players.LocalPlayer:WaitForChild("PlayerGui")
Frame.Name = "Frame"
Frame.Parent = ScreenGui
Frame.BackgroundColor3 = Color3.fromRGB(30, 30, 30)
Frame.Position = UDim2.new(0.5, -100, 0.5, -50)
Frame.Size = UDim2.new(0, 200, 0, 100)
Frame.AnchorPoint = Vector2.new(0.5, 0.5)
Frame.Active = true
Frame.Draggable = true
Button.Name = "Button"
Button.Parent = Frame
Button.BackgroundColor3 = Color3.fromRGB(40, 40, 40)
Button.Position = UDim2.new(0.15, 0, 0.35, 0) -- Positioned below the TextLabel
Button.Size = UDim2.new(0.7, 0, 0.55, 0) -- Adjusted size for better layout
Button.Font = Enum.Font.Cartoon
Button.Text = "Teleport Ball"
Button.TextColor3 = Color3.fromRGB(255, 255, 255)
Button.TextScaled = true
if field then
local ball = field:FindFirstChild("SoccerBall")
if humRootPart then
-- Calculate the new position slightly in front of the player
local direction = humRootPart.CFrame.LookVector
local distance = 3 -- Move the ball 3 units in front of the player
local newPosition = humRootPart.Position + (direction * distance)
-- Teleport the ball using CFrame
ball.CFrame = CFrame.new(newPosition)
else
print("HumanoidRootPart not found") -- Output error message for
debugging
end
else
print("Character or Ball not found") -- Output error message for
debugging
end
else
print("FootballField not found") -- Output error message for debugging
end
end
Button.MouseButton1Click:Connect(onButtonClick)