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

Help with Instance.new?

Asked by
FiredDusk 1466 Moderation Voter
8 years ago

What I am trying to do is if the player would click the part, a Point Light would add in it and if their mouse left the part, all PointLights would get removed.


game.Workspace.Part.ClickDetector.MouseClick:connect(function() local PointLight = Instance.new("PointLight", game.Workspace.Part) end) game.Workspace.Part.ClickDetector.MouseHoverLeave:connect(function() game.Workspace.Part:GetChildren():remove() end)

1 answer

Log in to vote
1
Answered by 8 years ago

All explaining done in the code.

--Your script
game.Workspace.Part.ClickDetector.MouseClick:connect(function()
        local PointLight = Instance.new("PointLight", game.Workspace.Part)
end)
--Edited
game.Workspace.Part.ClickDetector.MouseHoverLeave:connect(function()
    for _,v in pairs (game.Workspace.Part:GetChildren()) do -- Gather everything in that part
        if v:IsA("PointLight") then -- If it's a PointLight, don't wanna destroy any script's or anything do you?
            v:Destroy() -- Destroy it if it's a PointLight
        end -- End the if
    end -- End the in pairs
end) -- End the mouse hover

Please tell me if it doesn't work, didn't test it.

Ad

Answer this question