Local or Server scripts in the Game

I would need advice from experienced creators!

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???

examples from game:

Thanks for any advice
Cody

2 Likes

I would advise selecting all of the windows, giving them all a tag and then using Collection Service to make them work (on a server script)

3 Likes

I looked at several tutorials, and the Collection server with Tags is actually a Server script, but much simpler to create. Thanks

Honestly you should make these detections server side cuz you should never trust your client’s input. Just make it server side.

I am a 3D modeler and animator with 20 years of experience.
But I am an amateur in programming :upside_down_face:
so don’t laugh at my script :grinning:


-- 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

example video:

And how should I perform detections on the SERVER side ??
TAGs are placed on objects in the WORKSPACE !!



1 Like

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")

1 Like

Amazing.
I’m going to study it more and rebuild the game, for now it’s still possible.
Thank you very much
Cody

PS: the game prototype is here

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

External Code Editing:

Roblox Typescript

Probably recommend you to at least use external code editors. As it is actually very beneficial

1 Like