How would I make a script in a part run whenever a part is streamed into the workspace?
i.e, utilizing streaming enabled I want a script inside of a light to run on the client whenever the light part is loaded in. I can’t find anything else on this topic.
plz help
scripts in parts don’t automatically run when streamed in(or maybe I’m doing something wrong)
Hey!
Have you tried using game:IsLoaded()?
For example:
You will have to tick on the “Disabled” property of the script first!
while true do
if game:IsLoaded() then --this will check if the game is loaded or not.
game.Workspace.Part.Script.Disabled = false --this will enable your script.
break --stop the loop
end
wait(0.1)
end
If you get any errors/ problems, please report it back to me to see if I can help!
well problem is the script in the part doesn’t run at all after its streamed in and i’d like to keep the script contained in the part and only have it run locally.
local run = game:GetService("RunService")
local players = game:GetService("Players")
local player = players.LocalPlayer
local part = workspace:WaitForChild("Part")
if workspace.StreamingEnabled then
run.RenderStepped:Connect(function()
local distance = player:DistanceFromCharacter(part.Position)
if distance <= workspace.StreamingMinRadius then
--Do code.
end
end)
end
This is a client-side implementation although I believe it’s what you’re looking for.
and here’s a server-side implementation.
local run = game:GetService("RunService")
local players = game:GetService("Players")
local part = script.Parent
if workspace.StreamingEnabled then
while true do
run.Stepped:Wait()
for _, player in ipairs(players:GetPlayers()) do
local distance = player:DistanceFromCharacter(part.Position)
if distance <= workspace.StreamingMinRadius then
--Do code.
end
end
end
end