|
| 29 Dec 2016 06:44 PM |
if game.Workspace.Something then
end
i really don't even know where to start or even if that if statement will do anything |
|
|
| Report Abuse |
|
|
|
| 29 Dec 2016 06:47 PM |
if not game.Workspace:FindFirstChild("Whateverhere") then local i = Instance.new("Part") i.Parent = game.Workspace end |
|
|
| Report Abuse |
|
|
|
| 29 Dec 2016 06:59 PM |
okay let's build on that
let's say my script is pulling a model into workspace from lighting through a switch that you click to turn on and off
the problem is that if the player clicks fast enough even with the debounce the script switches to the wrong position and you can't remove the current model because it says none exists
i was hoping for some kind of safety
local db = false local sp = script.Parent
sp.ClickDetector.MouseClick:connect(function() sp.OnOff.Value=not sp.OnOff.Value if not db then db = true local c = game.Lighting.C:clone() local h = game.Lighting.H:clone() local p = game.Players:GetChildren() for i = 1, #p do if sp.OnOff.Value and (p[i].Name ~= script.Owner.Value)then game.Workspace.C:Destroy() h.Parent = game.Workspace else game.Workspace.H:Destroy() c.Parent = game.Workspace end wait(1) db = false end end end
end) |
|
|
| Report Abuse |
|
|
| |
|
treebee63
|
  |
| Joined: 16 Aug 2010 |
| Total Posts: 376 |
|
|
| 29 Dec 2016 08:03 PM |
Here are two approaches I would consider to solve this problem:
1. You can isolate "C" and "H" in their own model. This allows you to check inside the model to see if any duplicates exist. Hierachy: -(Workspace) "Workspace" -(Model) "ModelContainingCH" -(Object) "C" -(Object) "H" -... -... -...
2. You can store the "C" and "H" object currently inside of workspace in variables curr_H = h curr_H.Parent = workspace
curr_C = c curr_C.Parent = workspace
curr_H:Destroy() curr_C:Destroy()
|
|
|
| Report Abuse |
|
|
|
| 29 Dec 2016 08:04 PM |
" 2. You can store the "C" and "H" object currently inside of workspace in variables curr_H = h curr_H.Parent = workspace
curr_C = c curr_C.Parent = workspace
curr_H:Destroy() curr_C:Destroy()"
so like make a variable in addition to the actual C model?
but then how would i detect duplicates instead of just deleting the original? |
|
|
| Report Abuse |
|
|
treebee63
|
  |
| Joined: 16 Aug 2010 |
| Total Posts: 376 |
|
|
| 29 Dec 2016 08:16 PM |
| If you want to detect duplicates, you can sift through workspace for any models that are copies of either C or H. |
|
|
| Report Abuse |
|
|
|
| 29 Dec 2016 08:19 PM |
if not workspace:findFirstChild("MyObjectName",true) then --recursive myFunction() myCode end |
|
|
| Report Abuse |
|
|