Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do make a script search for a models location?

So between the If and Then statements I want something like "If MapContents is in workspace then" and "If MapContentsSmooth is in workspace then" but im not sure how to write that

wait(1)
function onClick()
	script.Parent.Sound:Play()
	wait(.1)
	
		if  then
game.Workspace.MapContents:Destroy()
game.Lighting.MapContentsSmooth:clone().Parent = game.Workspace
		else
			
		if then
game.Workspace.MapContentsSmooth:Destroy()
game.Lighting.MapContents:clone().Parent = game.Workspace
		end	
	end
end
script.Parent.ClickDetector.MouseClick:connect(onClick)

5 comments

0

Waht is it in Lighting? Place in server storage instead

0

Why serverstorage instead of lighting?

0

You can choose any however server storage is recommended. Lighting was frequently used way back in 2008 where there was no storage.

0

Because server storage is indebted for storage, whilst lighting is not. Is it LightingStorage or lighting? ServerStorage. Storage

0

This is not 2008.

1 answer

✓ Accepted answer

Hello, You know you could use "if workspace.Parent == "Place1(example)" then"or in some situations "if workspace.Parent.ClassName == "DataModel" then (example)".

Or you could use (as an example) if game:FindFirstChild("Workspace") which we will use now.

Or you could use if game.Workspace ~= nil (again, this is just an example)

In this situation it will look like this:

wait(1)
function onClick()
    script.Parent.Sound:Play()
    wait(.1)

        if workspace:FindFirstChild("MapContents") then
game.Workspace.MapContents:Destroy()
game.Lighting.MapContentsSmooth:Clone().Parent = game.Workspace -- :clone is deprecated, recommended using :Clone
        else
	
	if workspace:FindFirstChild("MapContents") then
game.Workspace.MapContentsSmooth:Destroy()
game.Lighting.MapContents:Clone().Parent = game.Workspace -- :clone is deprecated, recommended using :Clone
        end 
    end
end
script.Parent.ClickDetector.MouseClick:Connect(onClick) -- :connect is deprecated, recommended using :Connect

4 comments

0

Thank you, I was unfamiliar with that method

0

Eww you didn't fix the deprecated code

0

It's cause I didn't look deeper into the code, I edited it

0

I know

This discussion is preserved as it was. New answers, comments, and votes are closed.