Problem with my Client-sided door script

Hello, I’ve been working on a single-player game and am using a client-side approach to save server memory. Recently, I moved the ENTIRE map and GAME SYSTEMS to the client. However, I’m now encountering an issue where the controller script for doors has stopped functioning, even after changing it to a LocalScript.

local doorsFolder = script.Parent

local debounce = false
local debounceTime = 1.5

for _, door in ipairs(doorsFolder:GetChildren()) do
	if door:IsA("Model") then
		local openSound = door:FindFirstChild("door_open")
		local closeSound = door:FindFirstChild("door_close")
		local clickDetector = door:FindFirstChild("Click"):FindFirstChild("ClickDetector")

		local KEY_FOUND = door:FindFirstChild("KeyFound")
		local OPENED = door:FindFirstChild("Opened")

		if openSound and closeSound and clickDetector and KEY_FOUND and OPENED then
			clickDetector.MouseClick:Connect(function()
				if debounce then
					return
				end
				debounce = true
				task.spawn(function()
					if KEY_FOUND.Value then
						clickDetector.MaxActivationDistance = 0
					end
					task.wait(debounceTime)
					if not KEY_FOUND.Value then
						clickDetector.MaxActivationDistance = 10
					end
					debounce = false
				end)

				if KEY_FOUND.Value then
					if not OPENED.Value then
						OPENED.Value = true
						openSound:Play()

						for i = 1, 18 do
							door:SetPrimaryPartCFrame(door.PrimaryPart.CFrame * CFrame.Angles(0, math.rad(-5), 0))
							task.wait(0.02)
						end
					end
				else
					local lock_sound = door:FindFirstChild("door_locked")
					if lock_sound then
						lock_sound:Play()
					end
				end
			end)
		end
	end
end

This is how the model looks

image

Btw, the map is stored in ReplicatedStorage and cloned to workspace depending on the player’s level. Everything is on the client.

This is because your local script is parented inside of workspace. LocalScripts don’t run there.
You have to put them in a service where it does run like StarterGui, StarterCharacterScripts or StarterPlayerScripts

Copy your script and paste it inside Server Script and keep the same parent as the old local script

I’ve also tried putting the script into StarterGui or StarterPlayerScripts and it still does not work. I’ve added a new variable to detect when the map is cloned and find the doors, but it’s not even throwing an error or anything.

A bit off-topic, but I’d like to ask if you really know what you’re doing and want to do it. Transferring everything to the client is mostly a terrible idea. Anyone using third-party software can modify everything in the game. For example, it won’t be a problem to replace a few conditions in the if with just “true” in the script or even replace this script with another one that won’t check if the player has the key.

If you need to save server memory, I recommend checking out this tutorial or a few threads on the devforum that I found like this one or this one. (I think it was worth looking for other threads as well).

You should also see some security documents like this one.

Never trust the client.

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