Help with script

Hello everyone,
I am currently working on a drawer system but i have a problem that i want to fix. What i want is for the player to open the drawer and nobody else sees it as open until they open it. right now everyone can see every drawer that they didnt open

local doorOpen = false
local changingState = false
local sound = script.Parent.Interactive.DrawerSound
local delayTimer = 0

handle.ClickDetector.MouseClick:Connect(function(player, part)
	if not changingState then
		if doorOpen then
			changingState = true
			sound:Play()
			for i = 1, 16 do
				script.Parent:SetPrimaryPartCFrame(script.Parent.PrimaryPart.CFrame * CFrame.new(0, 0, 0.1))
			end
			changingState = false
			doorOpen = false
			delayTimer = 0  -- Reset the delay timer
		else
			changingState = true
			sound:Play()
			for i = 1, 16 do
				script.Parent:SetPrimaryPartCFrame(script.Parent.PrimaryPart.CFrame * CFrame.new(0, 0, -0.1))
			end
			changingState = false
			doorOpen = true
			delayTimer = 10  -- Set the delay timer to 10 seconds
			wait(10)  -- Wait for 10 seconds
			if delayTimer > 0 then
				-- If the timer wasn't canceled, close the door
				sound:Play()
				for i = 1, 16 do
					script.Parent:SetPrimaryPartCFrame(script.Parent.PrimaryPart.CFrame * CFrame.new(0, 0, 0.1))
				end
				doorOpen = false
				delayTimer = 0  -- Reset the delay timer
			end
		end
	end
end)

this is the individual script in each drawer.

Why you rely yourself saying it’s deleted :rofl:

If, as I assume, this is a server-side script, create an event in the local script where the box opens. This way, for other players, it will also be closed.

1 Like

how long have u been of devforum lol when you delete a post thats what comes up.

1 Like

thats the problem im having i cant figure out how to make it fully client-side.

1 Like

If you’re doing it entirely, you’ll basically have to do everything in a local script, which would be located in PlayerScript or StartedGui. Or, you could just transmit from the server script using RemoteEvent to the local script where the box will open.
In general understanding, you just need to create a RemoteEvent that activates a local script containing the same script you have. This script will only run for one player.

Well, to put it directly, something like this:
Server

local Event = game.ReplicatedStorage:WaitForChild("Event")

handle.ClickDetector.MouseClick:Connect(function(player, part)
	Event:FireServer(player)
end)

Local

local Event = game.ReplicatedStorage:WaitForChild("Event")
local doorOpen = false
local changingState = false
local sound = script.Parent.Interactive.DrawerSound
local delayTimer = 0
Event.OnClientEvent:Connect(function()
	if not changingState then
		if doorOpen then
			changingState = true
			sound:Play()
			for i = 1, 16 do
				script.Parent:SetPrimaryPartCFrame(script.Parent.PrimaryPart.CFrame * CFrame.new(0, 0, 0.1))
			end
			changingState = false
			doorOpen = false
			delayTimer = 0  -- Reset the delay timer
		else
			changingState = true
			sound:Play()
			for i = 1, 16 do
				script.Parent:SetPrimaryPartCFrame(script.Parent.PrimaryPart.CFrame * CFrame.new(0, 0, -0.1))
			end
			changingState = false
			doorOpen = true
			delayTimer = 10  -- Set the delay timer to 10 seconds
			wait(10)  -- Wait for 10 seconds
			if delayTimer > 0 then
				-- If the timer wasn't canceled, close the door
				sound:Play()
				for i = 1, 16 do
					script.Parent:SetPrimaryPartCFrame(script.Parent.PrimaryPart.CFrame * CFrame.new(0, 0, 0.1))
				end
				doorOpen = false
				delayTimer = 0  -- Reset the delay timer
			end
		end
	end
end)

But keep in mind that a local script can reset too, so you can use it in a separate GUI where you can disable the ‘ResetOnRespawn’ parameter.
Ah, and yes, if needed, you have to change the path to the box in the local script because it won’t be script.Parent there.

1 Like