Hi! I’m quite new to scripting and I’ve made a script that is rather… horrible but it works, and I need help in making it more efficient. Please don’t bombard me with concepts that are rather ‘advanced’ like raycasting, etc.
The process goes like this:
When a player enters a building with a floor, it’ll remove the roof by parenting the roof to ReplicatedStorage. Once the player leaves the building, it’ll touch on a brick named Outside which will return back the roof. Mind you this will happen LOCALLY so other players don’t see the roof disappearing. (Imagine like a topdown game)
Even though it works, it’ll send out this when the roof is empty in the output:
Roof is not a valid member of Model “Workspace.Building” - Client - Indoor:11
as the roof is in ReplicatedStorage. I think this will affect the performance in the long run, so is there any easy advice around this?
local FOOT = script.Parent:WaitForChild("LeftFoot")
local RS = game:GetService("ReplicatedStorage")
local STRING = script:WaitForChild("LOCATION")
FOOT.Touched:Connect(function(HIT)
STRING.Value = HIT.Name
print(STRING.Value)
if STRING.Value == "Floor" then
local MODEL = HIT.Parent
local ROOF = MODEL.Roof
ROOF.Parent = RS
else
if STRING.Value == "Outside" then
local MODEL = HIT.Parent
print(MODEL.Name)
local ROOF = MODEL:FindFirstChild("Roof")
if ROOF then
print("Present")
else
print("Roof")
local ORIGINAL = RS:FindFirstChild("Roof")
ORIGINAL.Parent = MODEL
end
end
end
end)
```