Load Models Named "Stand" Based On Player's Current Location

Hello,
I want to create a script where models named “Stand” are locally loaded and unloaded for the player based on their current location.
I understand that I should likely put them in lighting and need to load them based on how close the player gets to them but I don’t understand how to do this.
I am a relatively inexperienced scripter so I would appreciate any pointers on how I would do this or if there are any already made scripts of this sort that I can modify.
Thank you

2 Likes

Streaming

You can also use streaming to stream out the stands. If you don’t want other things to stream out, you can set everything else to persistent streaming. Instance Streaming | Documentation - Roblox Creator Hub

Manual way

To get started, try finding the Position of the player’s character then find the Position of the “Stand”. Since they are both Vector3’s you can simply subtract:

local unloadDistance = 50
local updateTime = 1

local Players = game:GetService("Players")

local player = Players.LocalPlayer

-- It's usually better to find the HumanoidRootPart's position instead of just the character's position
local humanoidRootPart = player.Character:FindFirstChild("HumanoidRootPart")
local stand = --[[insert here]]

local regularStandParent = stand.Parent

while true do
	local positionDifference = math.abs(humanoidRootPart.Position - stand.Position)

	if positionDifference > 50 then
		stand.Parent = nil
	else
		stand.Parent = regularStandParent
	end

	task.wait(updateTime)
end

If you have multiple stands you can loop through them inside the while true do loop with a for _, stand in ipairs(stands) do loop

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.