Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

I lock my door its locked for me only what do I do so it locks for everyone on filtering enabled?

Basicly my game is filtering enabled and this script is a Local Script inside of a gui button and it works but not as I want because when I lock the door it gets locked for me but for the other people its like if the door was unlocked how do I do so that its locked for everyone without turning off my filter

function onButtonClicked()
local x = game.Workspace:FindFirstChild("Home"..script.Parent.Parent.Parent.Parent.Name)
if not (x) then
return
else
if script.Parent.Text == "Lock Door" then
script.Parent.Text = "Unlock Door"
x.Home.FDoor.CanCollide = true
elseif script.Parent.Text == "Unlock Door" then
script.Parent.Text = "Lock Door"
x.Home.FDoor.CanCollide = false
end
end
end
script.Parent.MouseButton1Click:connect(onButtonClicked)

1 comment

0

Well FilteringEnabled is used to, block exploiters or prevent any changes to any Instance. So it's not best if you used FE for something you can actually change without converting it into FE if you're not planning to do so.

2 answers

Alright in order to have Client-Server communication you need to use remote events. Add this SCRIPT into ServerScriptService:

wait(1)

local event = Instance.new("RemoteEvent",game.ReplicatedStorage) -- inserting the event
event.Name = "Lock" -- Naming the event

event.OnServerEvent:connect(function(gamer) -- When the server is called 
	game.StarterGui.ScreenGui.HouseDoors.Text = "UnlockDoor"
	game.Workspace.Home.FDoor.CanCollide = true
end)

local eventt = Instance.new("RemoteEvent",game.ReplicatedStorage) -- inserting the event
eventt.Name = "UnLock" -- Naming the event

eventt.OnServerEvent:connect(function(gamer) -- When the server is called 
	game.StarterGui.ScreenGui.HouseDoors.Text = "Lock Door"
	game.Workspace.Home.FDoor.CanCollide = false
end)

Now update your local script:

function onButtonClicked()
local x = game.Workspace:FindFirstChild("Home"..script.Parent.Parent.Parent.Parent.Name)
if not (x) then
return
else
if script.Parent.Text == "Lock Door" then
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local LockEvent = ReplicatedStorage:WaitForChild("Lock")

LockEvent:FireServer(game.Players.LocalPlayer)
elseif script.Parent.Text == "Unlock Door" then
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local UnLockEvent = ReplicatedStorage:WaitForChild("UnLock")

UnLockEvent:FireServer(game.Players.LocalPlayer)
end
end
end
script.Parent.MouseButton1Click:connect(onButtonClicked)

This SHOULD work! Let me know if there is an issue because I will love to fix it. I haven't used events in a while.

4 comments

0

sorry sir but nothing works when I did these 2 things and now the button doesnt work anymore

0

Did you tweak the script? I put comments where you have to edit. Also let me know the errors.

0

ok so basicly I made a remote event inside of replicated storage and in server script service I added the script you gave me and inside of my local script in my gui buttin I added the other script now it doesnt work

0

I might be able to help you if you get in chat. You aren't understanding my code. You must edit it.

Remember that firstly, a localscript only runs on your client. Also, GUI-buttons only run on your client.

I advise to put a invisible roblox button with a roblox-button configured script over the normal gui and use the gui just for show. This is because roblox buttons runs on server meaning that it would open/lock for everyone.

This discussion is preserved as it was. New answers, comments, and votes are closed.