Thank you for taking the time to help me, it means a lot.
Here’s the entire script as I currently have it:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local UserInputService = game:GetService("UserInputService")
-- Create the character object and add it to the screengui
local character = Instance.new("ImageLabel")
character.Name = "Character"
character.Size = UDim2.new(0, 50, 0, 50)
character.BackgroundTransparency = 1 --added
character.Position = UDim2.new(0.5, -25, 0.9, -50)
character.Image = "rbxassetid://10666795198" -- Replace with the ID of the image you want to use for the character
character.Parent = script.Parent
-- Create the strawberry objects and add them to the screengui
local strawberries = {}
for i = 1, 5 do
local strawberry = Instance.new("ImageLabel")
strawberry.Name = "Strawberry"
strawberry.Size = UDim2.new(0, 25, 0, 25)
strawberry.BackgroundTransparency = 1 --added
strawberry.Position = UDim2.new(math.random(), -25, -0.1, 0)
strawberry.Image = "rbxassetid://11807642473" -- Replace with the ID of the image you want to use for the strawberries
strawberry.Parent = script.Parent
table.insert(strawberries, strawberry)
end
-- Function to move the character to the left
local function moveLeft()
local currentPos = character.Position
character.Position = UDim2.new(currentPos.X.Scale, currentPos.X.Offset - 5, currentPos.Y.Scale, currentPos.Y.Offset)
end
-- Function to move the character to the right
local function moveRight()
local currentPos = character.Position
character.Position = UDim2.new(currentPos.X.Scale, currentPos.X.Offset + 5, currentPos.Y.Scale, currentPos.Y.Offset)
end
-- Function to move the strawberries down
local function moveStrawberries()
for i, strawberry in ipairs(strawberries) do
local currentPos = strawberry.Position
strawberry.Position = UDim2.new(currentPos.X.Scale, currentPos.X.Offset, currentPos.Y.Scale, currentPos.Y.Offset + 5)
end
end
-- Function to check for collisions between the character and the strawberries
local function checkCollisions()
for i, strawberry in ipairs(strawberries) do
local characterPos = character.AbsolutePosition
local characterSize = character.AbsoluteSize
local strawberryPos = strawberry.AbsolutePosition
local strawberrySize = strawberry.AbsoluteSize
if characterPos.X < strawberryPos.X + strawberrySize.X and
characterPos.X + characterSize.X > strawberryPos.X and
characterPos.Y < strawberryPos.Y + strawberrySize.Y and
characterSize.Y + characterPos.Y > strawberryPos.Y then
-- Collision detected! Remove the strawberry and give the player a point
strawberry:Destroy()
table.remove(strawberries, i)
LocalPlayer.Data.Points.Value = LocalPlayer.Data.Points.Value + 1
end
end
end
local function resetGame()
-- Reset the game and add new strawberries
for i = 1, 5 do
task.wait(5)
--while #strawberries < 5 do
local strawberry = Instance.new("ImageLabel")
strawberry.Name = "Strawberry"
strawberry.Size = UDim2.new(0, 25, 0, 25)
strawberry.BackgroundTransparency = 1 --added
strawberry.Position = UDim2.new(math.random(), -25, -0.1, 0)
strawberry.Image = "rbxassetid://11807642473" -- Replace with the ID of the image you want to use for the strawberries
strawberry.Parent = script.Parent
table.insert(strawberries, strawberry)
end
end
-- Continuously reset the game and add new strawberries
RunService.RenderStepped:Connect(function()
resetGame()
end)
-- Connect the character movement functions to player input events
UserInputService.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.A then
moveLeft()
elseif input.KeyCode == Enum.KeyCode.D then
moveRight()
end
end)
-- Create the play button and start the game when it is clicked
local playButton = Instance.new("TextButton")
playButton.Name = "PlayButton"
playButton.Text = "Play"
playButton.Size = UDim2.new(0, 50, 0, 50)
playButton.Position = UDim2.new(0.5, -25, 0.5, -25)
playButton.Parent = script.Parent
playButton.MouseButton1Click:Connect(function()
-- Start the game
playButton.Visible = false
RunService.RenderStepped:Connect(function()
moveStrawberries()
checkCollisions()
resetGame()
end)
end)