I’m building a game where I have almost all the windows in the buildings in the city openable.
In essence, it is on local simple scripts with the help of ProximityPrompt
And now it works well so far, but there will be a few more houses with windows.
The question is ? I should get rid of local scripts on individual windows and start using one server script???
I am a 3D modeler and animator with 20 years of experience.
But I am an amateur in programming
so don’t laugh at my script
-- Služby --
local TweenService = game:GetService("TweenService")
-- Instatní --
local HLAVAK = script.Parent.Parent
local ProximityPrompts = HLAVAK["Prompts"] --------------
local nastaveni = HLAVAK.Nastaveni ---------
local Proxi = HLAVAK.PromptHolder.ProximityPrompt
-- Variabilní --
local proximityPrompts = {}
local connections = {}
local otevrit = HLAVAK.Zvuk.SOtevrit ----zvuk otevřeni
local zavrit = HLAVAK.Zvuk.SZavrit ----zvuk zavřeni
local hejbatko = nastaveni["Hejbatko"].Value ---
local cast1 = nastaveni["Pozice 1"].Value
local cframe1 = cast1.CFrame
local cast2 = nastaveni["Pozice 2"].Value
local cframe2 = cast2.CFrame
local tweenDuration = nastaveni["Cas"].Value
local OdstranenaCast = nastaveni["OdstranenaCast"].Value
local styl = nastaveni.Styl
local easingStyle = styl.EasingStyle.Value
local easingDirection = styl.EasingDirection.Value
local vychozi1
local tween
-- Funkce --
local function setup()
hejbatko.CFrame = cframe1
vychozi1 = true
if OdstranenaCast then
cast1:Destroy()
cast2:Destroy()
end
end
local function getProximityPrompts()
for index, child in pairs(ProximityPrompts:GetChildren()) do
if child:IsA("ObjectValue") then
local prompt = child.Value
if prompt:IsA("ProximityPrompt") then
table.insert(proximityPrompts, prompt)
end
end
end
end
local function tweenMovingPartTo(cframe)
if tween then
tween:Cancel()
tween:Destroy()
end
local tweenInfo = TweenInfo.new(tweenDuration, easingStyle, easingDirection)
tween = TweenService:Create(hejbatko, tweenInfo, {CFrame = cframe})
tween:Play()
end
local function onTriggered(player)
if vychozi1 then
print("vychozi1 = false")
vychozi1 = false
tweenMovingPartTo(cframe2)
Proxi.Enabled = false
otevrit.Playing = true
wait(2)
Proxi.ActionText = "CLOSE"
Proxi.Enabled = true
else
vychozi1 = true
tweenMovingPartTo(cframe1)
Proxi.Enabled = false
otevrit.Playing = true
wait(2)
Proxi.ActionText = "OPEN"
Proxi.Enabled = true
end
end
-- hlavni kod --
setup()
getProximityPrompts() ---- získání ProximityPrompts
for index, prompt in ipairs(proximityPrompts) do
local connection = prompt.Triggered:Connect(onTriggered)
table.insert(connections, connection)
end
Proximity prompt detections are built-in for server side, with a optional argument of player. It can check which player performed the action and uses the callback (the function you provide them. Then change whatever property want to achieve on the server side, as it will replicate to the client
Go look deeper for collectionservice methods. It doesn’t matter where the tag is placed, as you can still find it within CollectionService:GetTagged("YourTagName")
if you wanna go more advanced then use frameworks unless you got a good way to organize. It may seem dumb to use frameworks at the start, but it benefits you later.
Here are some popular frameworks if you have time to study.
Roblox Luau:
React-Roblox -Ui framework. Basically a copy of React but in lua
Knit -this doesn’t have intellisense unless with certain plugins, you can achieve some basic intellisense with it