Door open command script

Hello developers, I am trying to create an opening door script, so when a player runs a command, the door will open. I have the command script, however, when I try to open the door, it seems to not work.

Serverscript:

local groupid = 6418380
local grouprank = 0
local door = game.ReplicatedStorage.Door


game.Players.PlayerAdded:Connect(function(plr)
	plr.Chatted:Connect(function(msgenable)
		if msgenable == "!Door" then
			if plr:GetRankInGroup(groupid) >=grouprank then
				door:FireAllClients()
				print("Message Ran")
			end
		end
	end)
end)

Sever script in workspace

game.ReplicatedStorage.Door.OnServerEvent:Connect(function()
	if script.Parent.CanCollide == true then
		script.Parent.CanCollide = false
	else 
		script.Parent.CanCollide = true
	end
end)

Please let me know if you can find anything wrong with the script, as it is highly appriciated!

2 Likes

Why’s are you firing all clients in a local script? It’s fire server.

1 Like

So the problem is that you are firing all clients, but in the server script you’re waiting for the remote event to be OnServerEvent. If you’re not firing something by FireServer then OnServerEvent won’t pick up anything.

The top script you can do in a localscript, just change FireAllClients to FireServer:

local groupid = 6418380
local grouprank = 0
local door = game.ReplicatedStorage.Door -- your remote event

local plr = game:GetService("Players").LocalPlayer -- as we are in a local script we can get the player this way

plr.Chatted:Connect(function(msgenable)
	if msgenable == "!Door" then
		if plr:GetRankInGroup(groupid) >= grouprank then
			door:FireServer() -- fire to the server
			print("Message Ran")
		end
	end
end)

Make sure you put the localscript somewhere it can run, perhaps starterplayerscripts.

Server script: (The same)

game.ReplicatedStorage.Door.OnServerEvent:Connect(function()
	if script.Parent.CanCollide then -- can shorten this line without the "== true"
		script.Parent.CanCollide = false
	else 
		script.Parent.CanCollide = true
	end
end)

That should work as intended.

1 Like