I've made a racing game round script like a minigame. I'm asking how to make a functional finish game after touching that finish line. I tried to make it but there isn't a reaction. How could it be wrong?
This is a round script (all):
local replicatedstorage = game:GetService('ReplicatedStorage')
local status = replicatedstorage:WaitForChild('InfoValue')
local mapstorage = game.Workspace:WaitForChild ('StorageMaps')
local finish = mapstorage:FindFirstChild("FinishLine")
while true do
local mapsinserverstorage = game:GetService('ServerStorage'):GetChildren()
local chosenmap = mapsinserverstorage [math.random(1, #mapsinserverstorage)]
chosenmap:Clone().Parent = mapstorage
status.Value = 'Choosing a track.'
wait(2)
status.Value = 'Track chosen: ' ..chosenmap.Name
wait(2)
status.Value = 'Starting game.'
wait(2)
local spawns = chosenmap:WaitForChild('Spawns'):GetChildren()
for _, player in pairs (game.Players:GetPlayers()) do
if player and #spawns > 0 then
local torso = player.Character:WaitForChild('Torso')
local allspawns = math.random(1, #spawns)
local randomspawn = spawns[allspawns]
if randomspawn and torso then
table.remove(spawns, allspawns)
torso.CFrame = CFrame.new(randomspawn.Position + Vector3.new(0,2,0))
game.ReplicatedStorage.blockstart:Clone().Parent = game.Workspace
end
status.Value = 'Race is about to begin!'
wait(3)
end
for i = 3,1,-1 do
status.Value = '' ..i
wait(1)
end
game.Workspace.blockstart:remove()
status.Value = 'GO!'
wait(3)
end
status.Value = 'Race actually in progress.'
local player = chosenmap.FinishLine
player.FinishLine.Touched:connect(function(hit)
hit.Parent = nil
status.Value = 'The winner is: ' ..player.Name
end)
wait(180)
status.Value = 'Time is up. No one finished race!'
mapstorage:ClearAllChildren()
wait(3)
end
