kingtut7
|
  |
| Joined: 22 Apr 2012 |
| Total Posts: 8 |
|
|
| 17 Feb 2016 04:38 PM |
I made this code but when I step on the Regen button nothing happens! Can someone help?
local buttonPressed = false
Regen_Button.Touched:connect(function(hit) if not buttonPressed then -- Is it not pressed? local Regen_Button = game.Workspace["Regen_Button"]
function respawnCar() print("Respawning...") for _, object in pairs(game.Workspace:GetChildren()) do print(object.Name) if object.Name == "Race Car" then print("Race Car Found") end end local copyCar = game.ServerStorage["Race Car"]:Clone() copyCar.Parent = game.Workspace copyCar:MakeJoints() end end end) |
|
|
| Report Abuse |
|
|
|
| 17 Feb 2016 04:42 PM |
the function: respawnCar is never called. You just have it sitting in the Touched event. Functions do not trigger unless it called by respawnCar(). I would just take the function part out and remove an end and leave it as that.
|
|
|
| Report Abuse |
|
|
kingtut7
|
  |
| Joined: 22 Apr 2012 |
| Total Posts: 8 |
|
|
| 17 Feb 2016 04:49 PM |
I removed the function as you said but that didn't do anything.Here is the code now.
local buttonPressed = false
Regen_Button.Touched:connect(function(hit) if not buttonPressed then -- Is it not pressed? local Regen_Button = game.Workspace["Regen_Button"]
for _, object in pairs(game.Workspace:GetChildren()) do print(object.Name) if object.Name == "Race Car" then print("Race Car Found") end
local copyCar = game.ServerStorage["Race Car"]:Clone() copyCar.Parent = game.Workspace copyCar:MakeJoints() end end end) |
|
|
| Report Abuse |
|
|
|
| 17 Feb 2016 04:53 PM |
Looks like you're defining the button inside of the event for the instance that doesn't exist. Define Regen_Button at the top outside of the event so it knows what part to trigger the event for:
local buttonPressed = false
local Regen_Button = game.Workspace["Regen_Button"]
Regen_Button.Touched:connect(function(hit) if not buttonPressed then for _, object in pairs(game.Workspace:GetChildren()) do print(object.Name) if object.Name == "Race Car" then print("Race Car Found") end local copyCar = game.ServerStorage["Race Car"]:Clone() copyCar.Parent = game.Workspace copyCar:MakeJoints() end end end)
|
|
|
| Report Abuse |
|
|
kingtut7
|
  |
| Joined: 22 Apr 2012 |
| Total Posts: 8 |
|
|
| 17 Feb 2016 05:27 PM |
| But the Regen_Button is a part in my world not a variable. Whould that make a difference if I have to call it? |
|
|
| Report Abuse |
|
|
|
| 17 Feb 2016 05:35 PM |
because the code does not know it is a part. If I had a part in game.Workspace, I can not just type out:
print(MyPart.Name)
I have to define what that part is:
MyPart = game.Workspace.Part
print(MyPart.Name)
|
|
|
| Report Abuse |
|
|
kingtut7
|
  |
| Joined: 22 Apr 2012 |
| Total Posts: 8 |
|
|
| 17 Feb 2016 06:00 PM |
Thanks for that but when I stepped on the button, it spawned in so many cars that Roblox Crashed. Do you know how to fix that?
|
|
|
| Report Abuse |
|
|
kingtut7
|
  |
| Joined: 22 Apr 2012 |
| Total Posts: 8 |
|
|
| 17 Feb 2016 06:04 PM |
local buttonPressed = false
Regen_Button = game.Workspace.Regen_Button
Regen_Button.Touched:connect(function(hit) if not buttonPressed then -- Is it not pressed? local Regen_Button = game.Workspace["Regen_Button"]
for _, object in pairs(game.Workspace:GetChildren()) do print(object.Name) if object.Name == "Race Car" then print("Race Car Found") end
local copyCar = game.ServerStorage["Race Car"]:Clone() copyCar.Parent = game.Workspace copyCar:MakeJoints() end end end)
|
|
|
| Report Abuse |
|
|
|
| 17 Feb 2016 06:57 PM |
local Regen_Button = game.Workspace["Regen_Button"] Is the part called "Regen Button" or "Regen_Button"
|
|
|
| Report Abuse |
|
|
|
| 17 Feb 2016 07:07 PM |
The only reason it is spawning the vehicle more than once, is because you are hitting it more than once, therefore after it is hit you need to make cancollide = false
local buttonPressed = false
Regen_Button = game.Workspace.Regen_Button
Regen_Button.Touched:connect(function(hit) if not buttonPressed then Regen_Button.CanCollide = false local Regen_Button = game.Workspace["Regen_Button"]
for _, object in pairs(game.Workspace:GetChildren()) do print(object.Name) if object.Name == "Race Car" then print("Race Car Found") end
local copyCar = game.ServerStorage["Race Car"]:Clone() copyCar.Parent = game.Workspace copyCar:MakeJoints() end end end)
|
|
|
| Report Abuse |
|
|
kingtut7
|
  |
| Joined: 22 Apr 2012 |
| Total Posts: 8 |
|
|
| 17 Feb 2016 07:16 PM |
| Doing that had the same effect. Here is what happens: I start the game and when I walk over to the button I touch it and the Output goes crazy and the game crashes. |
|
|
| Report Abuse |
|
|
|
| 17 Feb 2016 07:18 PM |
After you touched it once, did you then fall through the regen block?
|
|
|
| Report Abuse |
|
|