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
We use cookies to offer you a better experience. By using Roblox.com, you are agreeing to our Privacy and Cookie Policy.
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: if something exists, prevent making another?

Previous Thread :: Next Thread 
DivineHate is not online. DivineHate
Joined: 29 May 2009
Total Posts: 28644
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
KritikalGunzz is not online. KritikalGunzz
Joined: 10 Nov 2013
Total Posts: 1633
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
DivineHate is not online. DivineHate
Joined: 29 May 2009
Total Posts: 28644
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
DivineHate is not online. DivineHate
Joined: 29 May 2009
Total Posts: 28644
29 Dec 2016 07:42 PM
halp ):
Report Abuse
treebee63 is not online. 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
DivineHate is not online. DivineHate
Joined: 29 May 2009
Total Posts: 28644
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 is not online. 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
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
29 Dec 2016 08:19 PM
if not workspace:findFirstChild("MyObjectName",true) then --recursive
myFunction()
myCode
end
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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