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