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()

for _, object in pairs (game.Workspace:GetChildren()) do

    print(object.Name)

    if object.Name == "Car" then

        print ("This is a car, we need to destroy it!")

        object:Destroy()

    end

end

end

function DestroyCars()

for _, object in pairs (game.ServerStorage:GetChildren()) do

    local carCopy = object:Clone()

    carCopy.Parent = game.Workspace

    carCopy:MakeJoints()

end

end

function ResetLights()

RedLight.Enabled = false

YellowLight.Enabled = false

GreenLight.Enbled = false   

end

function ResetBarrier()

Barrier.CanCollide = true

Barrier.Transparency = 0.5

end

function ResetLightCycle()

RedLight.Enabled = true

wait (1)  

RedLight.Enabled = false

YellowLight.Enabled = true

wait (1)

YellowLight.Enabled = false

GreenLight.Enabled = true    

end

function RemoveBarrier()

Barrier.Transparency = 1

Barrier.CanCollide = false

end

function ShowVictoryMessage (playerName)

local message = Instance.New("Message")

message.Text = playerName .. " has won!"

message.Parent = game.Workspace

wait(2)

message:Destroy()

end

function Checkpoint4Hit (OtherPart)

print ("Checkpoint4 was hit")

print (OtherPart.name)

if OtherPart ~= nil and OtherPart.Parent ~= nil and OtherPart.Parent:FindFirstChild ("Humanoid") then

    print ("A player hit me!")

    if not Checkpoint4:FindFirstChild(OtherPart.Parent.Name) and Checkpoint3:FindFirstChild 

(OtherPart.Parent.Name) then

        local playerTag = Instance.new("StringValue")

        playerTag.parent = Finish

        playerTag.name = OtherPart.Parent.Name

    end

end

end

Finish.Touched:connect(FinishHit)

function Checkpoint1Hit (OtherPart)

print ("Checkpoint1 was hit")

print (OtherPart.name)

if OtherPart ~= nil and OtherPart.Parent ~= nil and OtherPart.Parent:FindFirstChild ("Humanoid") then

    print ("A player hit me!")

    if Checkpoint1:FindFirstChild (OtherPart.Parent.Name) then

        local playerTag = Instance.new("StringValue")

        playerTag.parent = Checkpoint1

        playerTag.name = OtherPart.Parent.Name

    end

    if Finish:FindFirstChild (OtherPart.Parent.Name) and RaceInProgress then

        print ("Player wins!")

        RaceInProgress = false

        ShowVictoryMessage(OtherPart.Parent.Name)

    end

end

end

Checkpoint1.Touched:connect(Checkpoint1Hit)

function Checkpoint2Hit (OtherPart)

print ("Checkpoint2 was hit")

print (OtherPart.name)

if OtherPart ~= nil and OtherPart.Parent ~= nil and OtherPart.Parent:FindFirstChild ("Humanoid") then

    print ("A player hit me!")

    if not Checkpoint2:FindFirstChild(OtherPart.Parent.Name) and Checkpoint1:FindFirstChild 

(OtherPart.Parent.Name) then

        local playerTag = Instance.new("StringValue")

        playerTag.parent = Checkpoint2

        playerTag.name = OtherPart.Parent.Name

    end

end

end

Checkpoint2.Touched:connect(Checkpoint2Hit)

function Checkpoint3Hit (OtherPart)

print ("Checkpoint3 was hit")

print (OtherPart.name)

if OtherPart ~= nil and OtherPart.Parent ~= nil and OtherPart.Parent:FindFirstChild ("Humanoid") then

    print ("A player hit me!")

    if not Checkpoint3:FindFirstChild(OtherPart.Parent.Name) and Checkpoint2:FindFirstChild 

(OtherPart.Parent.Name) then

        local playerTag = Instance.new("StringValue")

        playerTag.parent = Checkpoint3

        playerTag.name = OtherPart.Parent.Name

    end

end

end

Checkpoint3.Touched:connect(Checkpoint3Hit)

function ClearCheckpoint(Checkpoint)

for _, object in pairs(Checkpoint:GetChildren()) do

if object.Name ~= "TouchInterest" then

    object:Destroy()

end

end

wait(10)

while true do

ResetLights()

ResetBarrier()

DestroyCars()

CreateCars()    

ClearCheckpoint(Checkpoint1)

ClearCheckpoint(Checkpoint2)

ClearCheckpoint(Checkpoint3)

ClearCheckpoint(Checkpoint4)

wait(10)

ResetLightCycle()

RemoveBarrier()

RaceInProgress = true

while RaceInProgress == true do

    wait()

end

wait(5)

end

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

Thanks.

Answer this question