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