Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Racing game help?

Tracks = game.Lighting.Tracks:GetChildren()
player = game.Players.LocalPlayer
Wtracks = game.Workspace


h = Instance.new("Hint", game.Workspace)
ingame = false
TestrackSPAWN = false

while true do
	h.Text = "Choosing Track!"
		wait(3)
		ranTrack = math.random(1, #Tracks)
		trackChosen = Tracks[ranTrack]
		h.Text = "Track Chosen is " .. trackChosen.Name -- The track was chosen
		wait(3)
		trackChosenClone = trackChosen:Clone()
		trackChosenClone.Parent = game.Workspace --Track is now in game
		if trackChosen.Name == "Testrack" then
			local Testrack = game.Workspace.Testrack
			local finish = game.Workspace.Testrack.finish
		 	local Blocker = game.Workspace.Testrack.Blocker
		    local poocrap = game.Workspace.Testrack.SpawnL
			ingame = true
			player.Character:MoveTo(poocrap.Position)
			--Countdown until race begins
			for i = 10, 1, -1 do
				h.Text = "Race begins in " .. i
				wait(1)
			end
			Blocker.Transparency = 1
			Blocker.CanCollide = false
			--Countdown until race runs out of time
			for i = 130, 1, -1 do
				h.Text = "Time left: " .. i
				wait(1)
				h.Text = "Race over, nobody finished.."
				trackChosenClone:Destroy()
			end
		end
		
	wait(1)
end

I'm making a racing game and I'm trying to figure out how to make a functional finish line. I've made a script that works like a minigame script to where it chooses a random track from a model named "Tracks" in my lighting folder that I made. I've been thinking on making the finish line brick have a onTouched event so when it's touched, it declares the winner via hint or message and destroys the copied workspace racetrack but the thing is, I don't know how to make a script that selects the finish line brick. I thought I should make a variable but I don't know how to make it select the finish line inside the racetrack that has just been copied into the Workspace.

tl:dr I need to help on how to find out to make a variable of a part inside a model that has just been copied into Workspace from Lighting.

It may sound complicated because I suck at explaining things but I really want to make this game. If you know how to do this, please answer.

1 answer

The simplest way is to give the finish line some good, unique name, like "FinishLine".

Then trackChosenClone.FinishLine will refer to that object in the clone.

You can then do whatever you want to the finish line:

local finishline = trackChosenClone.FinishLine

finishline.Touched:connect(function(hit)
	hit.Parent = nil
	-- destroy everything crossing the finish line?
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.