Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Can anyone spot any errors in this script and tell me why it won't work?

Asked by 10 years ago

local RedLight = game.Workspace.StartLight.RedModel.LightBulb.PointLight

local YellowLight = game.Workspace.StartLight.YellowModel.LightBulb.PointLight

local GreenLight = game.Workspace.StartLight.GreenModel.LightBulb.PointLight

local Barrier = game.Workspace.Wall

local RaceInProgress = false

local Checkpoint4 = game.Workspace.Checkpoint4

local Checkpoint1 = game.Workspace.Checkpoint1

local Checkpoint2 = game.Workspace.Checkpoint2

local Checkpoint3 = game.Workspace.Checkpoint3

function CreateCars()

01for _, object in pairs (game.Workspace:GetChildren()) do
02 
03    print(object.Name)
04 
05    if object.Name == "Car" then
06 
07        print ("This is a car, we need to destroy it!")
08 
09        object:Destroy()
10 
11    end
12 
13end

end

function DestroyCars()

1for _, object in pairs (game.ServerStorage:GetChildren()) do
2 
3    local carCopy = object:Clone()
4 
5    carCopy.Parent = game.Workspace
6 
7    carCopy:MakeJoints()
8 
9end

end

function ResetLights()

1RedLight.Enabled = false
2 
3YellowLight.Enabled = false
4 
5GreenLight.Enbled = false  

end

function ResetBarrier()

1Barrier.CanCollide = true
2 
3Barrier.Transparency = 0.5

end

function ResetLightCycle()

01RedLight.Enabled = true
02 
03wait (1
04 
05RedLight.Enabled = false
06 
07YellowLight.Enabled = true
08 
09wait (1)
10 
11YellowLight.Enabled = false
12 
13GreenLight.Enabled = true   

end

function RemoveBarrier()

1Barrier.Transparency = 1
2 
3Barrier.CanCollide = false

end

function ShowVictoryMessage (playerName)

1local message = Instance.New("Message")
2 
3message.Text = playerName .. " has won!"
4 
5message.Parent = game.Workspace
6 
7wait(2)
8 
9message:Destroy()

end

function Checkpoint4Hit (OtherPart)

1print ("Checkpoint4 was hit")
2 
3print (OtherPart.name)
4 
5if OtherPart ~= nil and OtherPart.Parent ~= nil and OtherPart.Parent:FindFirstChild ("Humanoid") then
6 
7    print ("A player hit me!")
8 
9    if not Checkpoint4:FindFirstChild(OtherPart.Parent.Name) and Checkpoint3:FindFirstChild

(OtherPart.Parent.Name) then

1        local playerTag = Instance.new("StringValue")
2 
3        playerTag.parent = Finish
4 
5        playerTag.name = OtherPart.Parent.Name
6 
7    end
8 
9end

end

Finish.Touched:connect(FinishHit)

function Checkpoint1Hit (OtherPart)

01print ("Checkpoint1 was hit")
02 
03print (OtherPart.name)
04 
05if OtherPart ~= nil and OtherPart.Parent ~= nil and OtherPart.Parent:FindFirstChild ("Humanoid") then
06 
07    print ("A player hit me!")
08 
09    if Checkpoint1:FindFirstChild (OtherPart.Parent.Name) then
10 
11        local playerTag = Instance.new("StringValue")
12 
13        playerTag.parent = Checkpoint1
14 
15        playerTag.name = OtherPart.Parent.Name
View all 29 lines...

end

Checkpoint1.Touched:connect(Checkpoint1Hit)

function Checkpoint2Hit (OtherPart)

1print ("Checkpoint2 was hit")
2 
3print (OtherPart.name)
4 
5if OtherPart ~= nil and OtherPart.Parent ~= nil and OtherPart.Parent:FindFirstChild ("Humanoid") then
6 
7    print ("A player hit me!")
8 
9    if not Checkpoint2:FindFirstChild(OtherPart.Parent.Name) and Checkpoint1:FindFirstChild

(OtherPart.Parent.Name) then

1        local playerTag = Instance.new("StringValue")
2 
3        playerTag.parent = Checkpoint2
4 
5        playerTag.name = OtherPart.Parent.Name
6 
7    end
8 
9end

end

Checkpoint2.Touched:connect(Checkpoint2Hit)

function Checkpoint3Hit (OtherPart)

1print ("Checkpoint3 was hit")
2 
3print (OtherPart.name)
4 
5if OtherPart ~= nil and OtherPart.Parent ~= nil and OtherPart.Parent:FindFirstChild ("Humanoid") then
6 
7    print ("A player hit me!")
8 
9    if not Checkpoint3:FindFirstChild(OtherPart.Parent.Name) and Checkpoint2:FindFirstChild

(OtherPart.Parent.Name) then

1        local playerTag = Instance.new("StringValue")
2 
3        playerTag.parent = Checkpoint3
4 
5        playerTag.name = OtherPart.Parent.Name
6 
7    end
8 
9end

end

Checkpoint3.Touched:connect(Checkpoint3Hit)

function ClearCheckpoint(Checkpoint)

1for _, object in pairs(Checkpoint:GetChildren()) do
2 
3if object.Name ~= "TouchInterest" then
4 
5    object:Destroy()
6 
7end

end

wait(10)

while true do

01ResetLights()
02 
03ResetBarrier()
04 
05DestroyCars()
06 
07CreateCars()   
08 
09ClearCheckpoint(Checkpoint1)
10 
11ClearCheckpoint(Checkpoint2)
12 
13ClearCheckpoint(Checkpoint3)
14 
15ClearCheckpoint(Checkpoint4)
View all 31 lines...

end

Please help, It would mean alot, I am almost done making my game.

Thanks.

Answer this question