Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Generated From Chat GPT-4
- -- Variables
- local plr = game.Players.LocalPlayer
- local uis = game:GetService("UserInputService")
- local rs = game:GetService("RunService")
- local footing = false
- local hasBall = false
- local ui -- this table will store the UI elements that we need
- local mode = Enum.UserInputState.Begin -- this enum value will keep track of whether the script is enabled or not
- -- Functions
- function getGoal()
- local dist, goal = 9e9
- for i,v in pairs(workspace:GetDescendants()) do
- if v.Name == "Lol" or v.Name == "Goal" then -- using the original names here
- local mag = (plr.Character.Torso.Position - v.Position).Magnitude
- if dist > mag then
- dist = mag; goal = v;
- end
- end
- end
- return goal
- end
- function getVector(goal)
- local dist = (plr.Character.Torso.Position - goal.Position).Magnitude
- return goal.Position + Vector3.new(0, 45 + (dist / 10)) - plr.Character.Humanoid.MoveDirection
- end
- function shootBall(vector) -- this is a local function that encapsulates the logic of shooting the ball
- if hasBall then
- local event = plr.Character.Basketball.shoot_event
- local unit = (vector - plr.Character.Head.Position).Unit
- local spawnPos = plr.Character.PrimaryPart.Position + unit * 3.8 -- using a number for spawn offset
- if spawnPos.Y - plr.Character.PrimaryPart.Position.Y < 4 then
- spawnPos = plr.Character.PrimaryPart.Position + unit * 4
- end
- event:FireServer(
- vector,
- spawnPos,
- "\240\159\148\165\240\159\148\165"
- )
- end
- end
- function handleJumped()
- task.wait(0.225) -- putting back the wait here
- shootBall(getVector(getGoal())) -- calling the local function here
- end
- function handleRender()
- local goal = getGoal()
- local dist = (plr.Character.Torso.Position - goal.Position).Magnitude
- if math.floor(dist) == 57 then -- this condition checks if we are at the desired location
- footing = true -- set footing to true
- plr.Character.Humanoid.Jump = true -- make the character jump
- else
- footing = false -- set footing to false
- plr.Character.Humanoid:MoveTo(goal.Position - Vector3.new(0, 0, 57)) -- move the character to a point near the goal with a distance of 57 units on the z-axis
- end
- if plr.Character and plr.Character:FindFirstChild("Basketball") then
- hasBall = true
- else
- hasBall = false
- end
- if hasBall then
- if footing then
- ui.label.TextColor3 = Color3.fromRGB(0, 255, 0) -- using color values here
- else
- ui.label.TextColor3 = Color3.fromRGB(255, 0, 0)
- end
- else
- ui.label.TextColor3 = Color3.fromRGB(157, 157, 157)
- end
- end
- -- Connections
- -- this function toggles the script on or off when F is pressed
- function handleKeybind(input)
- if input.KeyCode == Enum.KeyCode.F then -- check if the key pressed is F
- if mode == Enum.UserInputState.Begin then -- check if the script is enabled
- mode = Enum.UserInputState.End -- set the mode to disabled
- else -- otherwise, if the script is disabled
- mode = Enum.UserInputState.Begin -- set the mode to enabled
- end
- print("Script enabled:", mode == Enum.UserInputState.Begin) -- print the status of the script
- end
- end
- uis.InputBegan:Connect(handleKeybind) -- connect the function to the input event
- -- these connections only run when the script is enabled
- rs.Stepped:Connect(function()
- if mode == Enum.UserInputState.Begin then -- check if the script is enabled
- handleRender() -- run the render function
- end
- end)
- plr.Character.Humanoid.Jumping:Connect(function()
- if mode == Enum.UserInputState.Begin then -- check if the script is enabled
- handleJumped() -- run the jumped function
- end
- end)
- -- Initialization
- -- this function finds and stores the UI elements that we need in a table
- function initUI()
- ui = {} -- create an empty table for UI elements
- for i,v in pairs(plr.PlayerGui:GetDescendants()) do -- loop through all descendants of PlayerGui
- if v:IsA("TextLabel") and v.Text == "75" then -- find the text label with text "75"
- ui.label = v -- store it in the table with the key "label"
- break -- exit the loop since we found what we need
- end
- end
- assert(ui.label, "Label not found") -- check if we found the label, otherwise throw an error
- end
- initUI() -- call the function to initialize the UI elements
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement