Hello!
I'm making a racing game and i have problems with finish line code.
Wanted to made this like: If player have touched the finish line, then he will win race and round will be ended
I tried to make that but i have error after race starts: "FinishLine is not a valid member of Model"
Here are the round script that i made:
local replicatedstorage = game:GetService('ReplicatedStorage')
local status = replicatedstorage:WaitForChild('InfoValue')
local mapstorage = game.Workspace:WaitForChild ('StorageMaps')
local finish = mapstorage:FindFirstChild("FinishLine")
while true do
--[[
while game.Players.NumPlayers < 2 do
--status.Value = '2 or more players required to start the game. Invite some friends'
--repeat wait(2) until game.Players.NumPlayers >= 2
end
]]
for i = 15,0,-1 do
status.Value = 'New game starts in '..i
wait(1)
end
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()
game.ReplicatedStorage.FinishLine:Clone().Parent = game.Workspace
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

1 comment
Part of your problem is you don't use freaking 'tab'.