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

Script that deletes all point lights for a limited time?

Asked by
AmVolt 60
8 years ago

So I've been trying to work on a script that deletes all the pointlights in a game if you click and hold a certain brick for about 9 seconds. I've been having trouble with having them delete and then come back after 1 minute and 30 seconds. How can I do this? Everything I seem to try to do is not working.

Can you explain how to do this using simple bricks with pointlights and having them delete if you press and hold another brick. Thank you :)

0
Script Helpers, can you please show us some coding? iNicklas 215 — 8y
0
Honestly my coding just consisted of me desperately trying to use what I know to delete a simple pointlight from a brick. That's why I'm here looking for help. AmVolt 60 — 8y

1 answer

Log in to vote
0
Answered by
Marios2 360 Moderation Voter
8 years ago

Well, i don't know EXACTLY how your final script will be like (because i don't know how you can detect holding a brick with mouse). But i can give you an idea:

While the brick is being held, a BoolValuesomewhere both server and local can access gets set to true. A server script, using the Changed event of the BoolValue detects wether it is set to true or not and if true it moves all PointLights to ServerStorage (or somewhere a Part can be placed inside but without getting rendered or altered). After the brick is let go, the LocalScript (or some other script, if you'd prefer less local load) will set said BoolValue to false. The server script will then detect that it's false and restore all PointLights back to Workspace, exactly where they were left before.

If you wanted to delete, i thought of something, but it'd be less effecient script-wise. The way i told you right now is much simplier to do, as a Part placed inside Replicated/ServerStorage essensially functions as if you had used the Remove() function on it, except all scripts can recall the Part anytime.

Bonus Note: For extra effeciency, put the PointLights inside a Folder, so instead of searching all the Workspace for the PointLights, the children of said Folder just get easily picked up! Make sure to have a Folder of the same name in the destination, for more effeciency.

So it looks like this:

Part hold boolean

local lights = game.ServerStorage.Lights:GetChildren()
--(UserInputService thing in LocalScript/Server Script)
repeat wait() until #lights == 0 --Wait for lights to exist in Workspace
game.ReplicatedStorage.Held.Value = true
--(Brick is not held anymore)
game.ReplicatedStorage.Held.Value = false
end

Server script handling PointLights

game.ReplicatedStorage.Held.Changed:connect(function(bool)
if bool == true then
for _,part in pairs(workspace.Lights:GetChildren()) do
part.Parent = game.ServerStorage.Lights
end
else
wait(3) --Delay for returning
for _,part in pairs(game.ServerStorage.Lights:GetChildren()) do
part.Parent = workspace.Lights
end
end
end)

Here you go! That's just how it should work! Once you add the way the BoolValue gets triggered, no problem afterwards!

EDIT - Added precisely what asker was asking for, made overall answer fancier

0
Ok great! So where would I add the Wait Value if I wanted to have it stay in the Replicated Storage for a limited time before returning? AmVolt 60 — 8y
0
I edited my post for your thing. In addition, using # before a table name returns the number of items inside it. Marios2 360 — 8y
Ad

Answer this question