Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How do make a script search for a models location?

Asked by 5 years ago

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)
0
Waht is it in Lighting? Place in server storage instead User#19524 175 — 5y
0
Why serverstorage instead of lighting? User#23462 0 — 5y
0
You can choose any however server storage is recommended. Lighting was frequently used way back in 2008 where there was no storage. mudathir2007 157 — 5y
0
Because server storage is indebted for storage, whilst lighting is not. Is it LightingStorage or lighting? ServerStorage. Storage User#19524 175 — 5y
0
This is not 2008. User#19524 175 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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
0
Thank you, I was unfamiliar with that method User#23462 0 — 5y
0
Eww you didn't fix the deprecated code User#19524 175 — 5y
0
It's cause I didn't look deeper into the code, I edited it mudathir2007 157 — 5y
0
I know mudathir2007 157 — 5y
Ad

Answer this question