generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: ROBLOX Racing Script

Previous Thread :: Next Thread 
coolbart97thehero is not online. coolbart97thehero
Joined: 09 Dec 2011
Total Posts: 7
28 Sep 2014 04:29 AM
In the following of the ROBLOX University lessons, I made this script for racing. Everything worked fine, but since I have added the part about checkpoints, nothing works anymore. I can't do a "Play Solo" or a "Run" to check on which line I went wrong, because then I get an error message. I checked all the locals, and they seem just fine. Can anyone tell me what is wrong with my script?

Script:
local checkpoint1 = game.Workspace.Checkpoint1
local checkpoint2 = game.Workspace.Checkpoint2
local checkpoint3 = game.Workspace.Checkpoint3

local respawnCarsBlock = game.Workspace.RespawnCarsBlock

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 startBarrier = game.Workspace.StartBarrier

function respawnCars()
print("I am going to respawn the cars now.")
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
for _, object in pairs(game.ServerStorage:GetChildren()) do
local carCopy = object:Clone()
carCopy.Parent = game.Workspace
carCopy:MakeJoints()
end
end

respawnCarsBlock.Touched:connect(respawnCars)


function showVictoryMessage(playerName)
local message = Instance.new("Message")
message.Text = playerName .. " has won!"
message.Parent = game.Workspace
wait(2)
message:Destroy()
end


function checkpoint1hit(otherPart)
print("Checkpoint 1 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 checkpoint1:FindFirstChild(otherPart.Parent.Name) then
endlocal playerTag = Instance.new("StringValue")
playerTag.Parent = checkpoint1
playerTag.Name = otherPart.Parent.Name
end

if checkpoint3:FindFirstChild(otherPart.Parent.Name) then
print("Player wins!")
showVictoryMessage(otherPart.Parent.Name)
end
end
end

function checkpoint2hit(otherPart)
print("Checkpoint 2 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
endlocal playerTag = Instance.new("StringValue")
playerTag.Parent = checkpoint2
playerTag.Name = otherPart.Parent.Name
end
end
end

function checkpoint3hit(otherPart)
print("Checkpoint 3 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
endlocal playerTag = Instance.new("StringValue")
playerTag.Parent = checkpoint3
playerTag.Name = otherPart.Parent.Name
end
end
end

checkpoint1.Touched:connect(checkpoint1hit)
checkpoint2.Touched:connect(checkpoint2hit)
checkpoint3.Touched:connect(checkpoint3hit)

wait (10)

redLight.Enabled = true

wait (5)

redLight.Enabled = false
yellowLight.Enabled = true

wait (2)

yellowLight.Enabled = false
greenLight.Enabled = true
startBarrier.Transparency = 1
startBarrier.CanCollide = false
Report Abuse
Jpoppycat is not online. Jpoppycat
Joined: 28 Aug 2011
Total Posts: 351
28 Sep 2014 04:32 AM
Maybe you have forgotten to name a part by the names listed under the locals ?
Or deleted.
Report Abuse
coolbart97thehero is not online. coolbart97thehero
Joined: 09 Dec 2011
Total Posts: 7
28 Sep 2014 04:34 AM
The parts are all fine
Report Abuse
bob10110 is not online. bob10110
Joined: 09 Dec 2007
Total Posts: 679
28 Sep 2014 05:06 AM
Found a potential issue! Look at this section of code:

----

function checkpoint1hit(otherPart)
print("Checkpoint 1 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 checkpoint1:FindFirstChild(otherPart.Parent.Name) then
endlocal playerTag = Instance.new("StringValue")
playerTag.Parent = checkpoint1
playerTag.Name = otherPart.Parent.Name
end

----

Notice anything weird? Here, I'll point it out a bit more clearly:

----

endlocal playerTag = Instance.new("StringValue")

----

The compiler isn't recognizing that "end", and since you have open-ended functions without their respective ends, that's where your errors are coming from.
Report Abuse
coolbart97thehero is not online. coolbart97thehero
Joined: 09 Dec 2011
Total Posts: 7
28 Sep 2014 06:57 AM
Thank you very much, that was the problem indeed. And now I also found the option to find the script error.
Report Abuse
coolbart97thehero is not online. coolbart97thehero
Joined: 09 Dec 2011
Total Posts: 7
28 Sep 2014 08:49 AM
Yup, that was all!
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image