here, whole client matchmaking code…
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")
local SoundService = game:GetService("SoundService")
local UserInputService = game:GetService("UserInputService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local PlayerGui = player:WaitForChild("PlayerGui")
local MinigameUI = PlayerGui:WaitForChild("MinigameUI")
local BeforeStartCountdown = MinigameUI:WaitForChild("Countdown")
local inGameCountdown = MinigameUI:WaitForChild("CountdownMiniGame")
local ResultUI = MinigameUI:WaitForChild("ResultUI") -- Result UI for showing the score after the game ends
local points = 0
local TweenService = game:GetService("TweenService")
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local KickingUI = PlayerGui:WaitForChild("Football_KickerFrame")
local Bar = KickingUI:WaitForChild("Bar")
local Arrow = Bar:WaitForChild("Arrow")
local Target = Bar:WaitForChild("Target")
local arrowTween
-- References for ball and animation
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local football = ReplicatedStorage:WaitForChild("Football")
local FootballEvent = ReplicatedStorage:WaitForChild("1V1"):WaitForChild("FootballEvent") -- RemoteEvent to notify server
local playKickAnimationEvent = ReplicatedStorage:WaitForChild("1V1"):WaitForChild("KickAnimation")
local footballMissEvent = ReplicatedStorage:WaitForChild("1V1"):WaitForChild("FootballMissEvent")
local soundFolder = SoundService:WaitForChild("LowTaperFade") -- Replace with the name of your folder containing sounds
local imageFolder = ReplicatedStorage:WaitForChild("LowTaperFade")
local images = imageFolder:GetChildren()
local currentSound = nil
local frame = ResultUI
local button = frame:WaitForChild("ExitButton") -- Replace with your button's name
local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)
-- Define positions
local startPosition = UDim2.new(0.339, 0, -0.5, 0) -- Start position (off-screen)
local targetPosition = UDim2.new(0.339, 0, 0.181, 0) -- Target position
-- Set the frame's initial position
frame.Position = startPosition
-- Tween the frame down
local tweenDown = TweenService:Create(frame, tweenInfo, { Position = targetPosition })
-- Tween the frame back up
local tweenUp = TweenService:Create(frame, tweenInfo, { Position = startPosition })
local confettiFrame = MinigameUI:WaitForChild("GameClick") -- Fullscreen frame to contain confetti
local confettiColors = {
Color3.fromRGB(255, 0, 0), -- Red
Color3.fromRGB(0, 255, 0), -- Green
Color3.fromRGB(0, 0, 255), -- Blue
Color3.fromRGB(255, 255, 0), -- Yellow
Color3.fromRGB(255, 165, 0), -- Orange
Color3.fromRGB(128, 0, 128) -- Purple
}
-- Function to create a confetti piece
local function createConfettiPiece()
local confettiPiece = Instance.new("Frame")
confettiPiece.Size = UDim2.new(0, math.random(10, 20), 0, math.random(20, 40)) -- Slightly wider strips
confettiPiece.Position = UDim2.new(math.random(), 0, -0.1, 0) -- Random horizontal spawn, above screen
confettiPiece.BackgroundColor3 = confettiColors[math.random(1, #confettiColors)] -- Random color
confettiPiece.BorderSizePixel = 0
confettiPiece.Rotation = math.random(0, 360) -- Initial random rotation
confettiPiece.Parent = confettiFrame
-- Tween to make the confetti fall with physics-like easing
local fallDuration = math.random(3, 6) -- Slow fall duration
local fallTweenInfo = TweenInfo.new(
fallDuration,
Enum.EasingStyle.Linear,
Enum.EasingDirection.InOut
)
local fallGoal = { Position = UDim2.new(confettiPiece.Position.X.Scale, 0, 1.1, 0) } -- Fall off the screen
local fallTween = TweenService:Create(confettiPiece, fallTweenInfo, fallGoal)
-- Slight rotation during the fall
local rotationTweenInfo = TweenInfo.new(
fallDuration,
Enum.EasingStyle.Linear,
Enum.EasingDirection.InOut
)
local rotationGoal = { Rotation = confettiPiece.Rotation + math.random(-90, 90) }
local rotationTween = TweenService:Create(confettiPiece, rotationTweenInfo, rotationGoal)
-- Play the tweens
fallTween:Play()
rotationTween:Play()
-- Cleanup the confetti piece after it falls
fallTween.Completed:Connect(function()
confettiPiece:Destroy()
end)
end
-- Function to generate confetti rain
local function startConfettiRain()
for i = 1, 100 do -- Number of confetti pieces
task.spawn(function()
createConfettiPiece()
wait(math.random(0, 50) / 1000) -- Slight delay between spawns for randomness
end)
end
end
local function setRandomImage()
-- Get all images in the folder
local images = imageFolder:GetChildren()
-- Check if there are any images in the folder
if #images > 0 then
-- Pick a random image
local randomImage = images[math.random(1, #images)]
-- Ensure it's a valid StringValue with an Image ID
if randomImage:IsA("StringValue") then
ResultUI.Tie.Image = "rbxassetid://" .. randomImage.Value
else
warn("Selected image is not a valid StringValue with an image ID.")
end
else
warn("No images found in LowTaperFade folder!")
end
end
-- Function to play a random sound
local function playRandomSound()
-- Get all sounds in the folder
local sounds = soundFolder:GetChildren()
if #sounds > 0 then
-- Pick a random sound
local randomSound = sounds[math.random(1, #sounds)]
if randomSound:IsA("Sound") then
-- Stop the previous sound (if any)
if currentSound and currentSound.IsPlaying then
currentSound:Stop()
end
-- Play the new sound and set it as the current sound
randomSound:Play()
currentSound = randomSound
else
warn("Randomly selected item is not a Sound.")
end
else
warn("No sounds found in the folder.")
end
end
-- Example usage: Call the function
local function createNewTarget()
Target.Position = UDim2.new(math.random((1-Target.Size.X.Scale)*1000)/1000, 0, 0, 0) -- random position
if not arrowTween then
local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, -1, true)
arrowTween = TweenService:Create(Arrow, tweenInfo, {Position = UDim2.new(1, 0, 0, 0)})
end
arrowTween:Play()
end
createNewTarget()
local deb = false
local debclick = false
local function playKickAnimation()
-- Assuming you have an animation in the player's humanoid
local kickAnimation = Instance.new("Animation")
kickAnimation.AnimationId = "rbxassetid://100710361198380" -- Replace with actual animation ID
local track = humanoid:LoadAnimation(kickAnimation)
track:Play()
end
local function kickFootball()
-- Fire RemoteEvent to server to create football
FootballEvent:FireServer(character.HumanoidRootPart.Position + Vector3.new(0, 2, 5)) -- Position in front of the player
-- Optional: Add a slight delay to allow football to be created before the next action
wait(1)
end
-- Function to start the minigame countdown (3-2-1)
local countdownText = BeforeStartCountdown
countdownText.TextColor3 = Color3.fromRGB(255, 255, 255)
-- Add sound effects for each countdown change
local countdownSound = game.SoundService.Boom
-- Flashy Countdown Animation Function
local function startCountdown(startTime)
countdownText.Visible = true
local countdownTime = startTime or 10 -- Default to 10 if no time is provided
local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut) -- Smooth tween animation
for i = countdownTime, 1, -1 do
countdownText.Text = tostring(i)
-- Calcul
-- Play sound
countdownSound:Play()
-- Wait for the tween to complete and for 1 second
wait(1)
end
-- Final Countdown (0)
countdownText.Text = "GO!"
countdownText.TextColor3 = Color3.fromRGB(255, 255, 255) -- Green color
wait(1)
countdownText.Text = "" -- Clear the text after 1 second
end
-- Function to start the game countdown (30 seconds)
local function startGameCountdown()
local timeRemaining = 30 -- Start the countdown from 30 seconds
inGameCountdown.Visible = true
while timeRemaining > 0 do
inGameCountdown.Text = "Time Remaining: " .. timeRemaining
if timeRemaining <= 10 then
SoundService.Boom:Play() -- Play dramatic sound every second in the last 10 seconds
end
wait(1)
timeRemaining = timeRemaining - 1
end
inGameCountdown.Visible = false
end
KickingUI.Bar.TextButton.MouseButton1Click:Connect(function(plr)
if not deb then
deb = true
arrowTween:Pause()
playKickAnimationEvent:FireServer()
-- Check if player is in range
if Target.Position.X.Scale < Arrow.Position.X.Scale and Arrow.Position.X.Scale < Target.Position.X.Scale + Target.Size.X.Scale then
print("In range")
-- Play kick animation and kick the football
playKickAnimation()
kickFootball()
points += 1
else
print("Not in range")
-- Even if not in range, kick the football
playKickAnimation()
footballMissEvent:FireServer()
end
wait(1) -- Prevent rapid clicks
createNewTarget()
deb = false -- Reset debounce
end
end)
-- Listen for the start of the minigame
ReplicatedStorage.StartMinigameEvent.OnClientEvent:Connect(function(opponent)
points = 0
print("Minigame started.")
-- Start the 3-2-1 countdown
startCountdown(3)
-- Start the game countdown
KickingUI.Bar.Visible = true
startGameCountdown()
KickingUI.Bar.Visible = false
print("Minigame ended.")
-- Send the points to the server for both players
ReplicatedStorage.EndMinigameEvent:FireServer(points)
end)
-- Receive the game results from the server
ReplicatedStorage.EndMinigameEvent.OnClientEvent:Connect(function(yourPoints, theirPoints)
--print("Minigame result received. Your points: " .. yourPoints .. ", Opponent's points: " .. theirPoints)
print("Type of yourPoints: ", typeof(yourPoints))
ResultUI.Visible = true
tweenDown:Play()
task.wait(1)
ResultUI.YourPoints.Text = "Your Points: " .. yourPoints.Value
ResultUI.TheirPoints.Text = "Opponent's Points: " .. theirPoints.Value
if yourPoints > theirPoints then
confettiFrame.Visible = true
startConfettiRain()
ResultUI.Result.Text = "You Won!"
ResultUI.Won.Visible = true
SoundService:WaitForChild("Confetti"):Play()
ReplicatedStorage:WaitForChild("1V1"):WaitForChild("CashYummy"):FireServer(player)
elseif yourPoints < theirPoints then
ResultUI.Result.Text = "You Lost!"
ResultUI.Lost.Visible = true
else
setRandomImage()
ResultUI.Result.Text = "It's a Tie!"
playRandomSound()
ResultUI.Tie.Visible = true
end
end)
button.MouseButton1Click:Connect(function()
ResultUI.Lost.Visible = false
ResultUI.Won.Visible = false
ResultUI.Tie.Visible = false
confettiFrame.Visible = false
tweenUp:Play()
tweenUp.Completed:Wait()
ResultUI.Visible = false
if currentSound and currentSound.IsPlaying then
currentSound:Stop()
print("Sound stopped.")
else
print("No sound is currently playing.")
end
end)