Remote Event: Gate Control Acess

I want to make an script where it identies the tool of the user that is holding and if the item is permitted, the gate opens, for that I would need the Character from the player which I acess it from LocalScript, after that, it goes for the ServerScript and does the job of opening it.
Both scripts are at same model.

There is no output errors, there is also no prints in the output.

EnableEvent (LocalScript)

local Event = script.Parent.Open
local HackEvent = script.Parent.OpenHack

local Player = game:GetService("Players").LocalPlayer

-- Cl
local clearance = {
	"[CCI] CID - III",
	"[CCI] CID - IV",
	"[CCI] CID - V",
	"[CCI] Combative Card",
	"[GOI] CID - III",
}

local HackClearance = {
	"Hacking Device III",
	"Hacking Device IV",
}

local PH = {
	"[CCI] CID - 0",
	"[CCI] CID - I",
	"[CCI] CID - II",
	"[GOI] CID - II",
	"Hacking Device II",
}

-- Bools
local Countdown = script.Parent.Countdown

-- Prompts
local Reader1 = script.Parent.Reader1
local Reader2 = script.Parent.Reader2

local Prompt1 = Reader1.Light.ID
local Prompt1e = Reader1.Light.Hack.Hack
local Prompt2 = Reader2.Light.ID	
local Prompt2e = Reader2.Light.Hack.Hack

-- Function

local function EventHandler()
	print("Function Worked")
	if Countdown.Value == false then
		print("Countdown is False")
		for _, item in pairs(Player.Character:GetDescendants()) do
			print("Found itens")
			if table.find(clearance, item.Name) then
				print("Clearence Found")
				Event:FireServer("Accepted")
			elseif table.find(PH, item.Name) then
				print("PH Found")
				Event:FireServer("Refused")
			end
		end
	end
end

local function HackHandler()
	if Countdown.Value == false then
		for _, item in pairs(Player.Character:GetDescendants()) do
			if table.find(HackClearance, item.Name) then
				HackEvent:FireServer()
			end
		end
	end
end


Prompt1.Triggered:Connect(function()
	EventHandler()
end)

Prompt2.Triggered:Connect(function()
	EventHandler()
end)

Prompt1e.Triggered:Connect(function()
	HackHandler()
end)

Prompt2e.Triggered:Connect(function()
	HackHandler()
end)

EventReceiver (Server Side Script)

local Event = script.Parent.Open
local HackEvent = script.Parent.OpenHack

local Gate = script.Parent
local Reader1 = Gate.Reader1
local Reader2 = Gate.Reader2

local Bool = Gate.Opened

-- Gate Mode
local Door = Gate.Gate
local ExemptDoor = Gate.UG
local Bool = Gate.Opened
local Sound = Door.Open
local Accept = Door.Accept
local Refuse = Door.Refuse

-- Reader's Mode
local Light1 = Reader1.Light
local Light2 = Reader2.Light
local Prompt1 = Light1.ID
local Prompt2 = Light2.ID

-- Tween
local countdown = 6
local CountBool = Gate.Countdown
local TS = game:GetService("TweenService")
local TInfo = TweenInfo.new(6)

local GateOpen = {CFrame = Door.CFrame}
local GateClose = {CFrame = ExemptDoor.CFrame}
local TOpen = TS:Create(Door, TInfo, GateOpen)
local TClose = TS:Create(Door, TInfo, GateClose)

-- Functions

local function Up()
	CountBool.Value = true
	Prompt1.Enabled = false
	Prompt2.Enabled = false
	Accept:Play()
	Light1.BrickColor = BrickColor.new("Lime green")
	Light2.BrickColor = BrickColor.new("Lime green")
	Sound:Play()
	TOpen:Play()
	wait(1)
	Light1.Color = Color3.new(0.372549, 0.368627, 0.368627)
	Light2.Color = Color3.new(0.372549, 0.368627, 0.368627)
	Bool.Value = true
	CountBool.Value = false
	Prompt1.Enabled = true
	Prompt2.Enabled = true
end

local function Down()
	CountBool.Value = true
	Prompt1.Enabled = false
	Prompt2.Enabled = false
	Accept:Play()
	Light1.BrickColor = BrickColor.new("Lime green")
	Light2.BrickColor = BrickColor.new("Lime green")
	Sound:Play()
	TClose:Play()
	wait(1)
	Light1.Color = Color3.new(0.372549, 0.368627, 0.368627)
	Light2.Color = Color3.new(0.372549, 0.368627, 0.368627)
	Bool.Value = false
	CountBool.Value = false
	Prompt1.Enabled = true
	Prompt2.Enabled = true
end

local function Refused()
	CountBool.Value = true
	Prompt1.Enabled = false
	Prompt2.Enabled = false
	Light1.BrickColor = BrickColor.new("Really red")
	Light2.BrickColor = BrickColor.new("Really red")
	Refuse:Play()
	wait(1)
	Light1.Color = Color3.new(0.372549, 0.368627, 0.368627)
	Light2.Color = Color3.new(0.372549, 0.368627, 0.368627)
	CountBool.Value = false
	Prompt1.Enabled = true
	Prompt2.Enabled = true
end

Event.OnServerEvent:Connect(function(player, itemName)
	print("Received event:", itemName)
	if CountBool.Value == false then
		if itemName == "Accepted" then
			if Bool.Value == true then
				Down()
			else
				if Bool.Value == false then
					Up()
				end
			end
		elseif itemName == "Refused" then
			Refused()
		end
	end
end)

HackEvent.OnServerEvent:Connect(function()
	if CountBool.Value == false then
		if Bool.Value == true then
			Down()
		elseif Bool.Value == false then
			Up()
		end
	end
end)
4 Likes

Is event in replicated storage? If so then move script out of RS. Any scripts (except modulescripts) wouldnt work there

3 Likes

None of the scripts are inside ReplicatedStorage, they’re both in same model which are found inside Workspace

1 Like

whats need of puting scripts in workspace?? and whats point of puting remote/bindable events/functions not in RS???

1 Like

If it was an general script, I would put. But the scripts defines an singular model, which there will be alot of same models.

1 Like

thats why putting scripts in workspace is bad. And putting many models with same scripts
is bad too bc you will not be able to normally update all the scripts if you have 500 same models, better using ModuleScript’s

1 Like

But that wouldn’t case all the gates opening at same time?
I’ve never used an module script, so I might wrong about this.

If you would do everything right through ModuleScript all the gates should work as you want

I’ve followed your idea, however, it seems that happens to same situation to an module script, the character can’t be found with an module.

local GateModule = {}
local Player = game:GetService("Players").LocalPlayer

-- Cl
local clearance = {
	"[CCI] CID - III",
	"[CCI] CID - IV",
	"[CCI] CID - V",
	"[CCI] Combative Card",
	"[GOI] CID - III",
}

local HackClearance = {
	"Hacking Device III",
	"Hacking Device IV",
}

local PH = {
	"[CCI] CID - 0",
	"[CCI] CID - I",
	"[CCI] CID - II",
	"[GOI] CID - II",
	"Hacking Device II",
}



function GateModule.EventInspection(Refuse,CountBool,Prompt1,Prompt2,Prompt1e,Prompt2e,Accept,Light1,Light2,Sound,TOpen,Bool,TClose)
	local Character = Player.Character
	for _, item in pairs(Character:GetDescendants()) do
		if table.find(clearance, item.Name) then
			if Bool.Value == true then
				CountBool.Value = true
				Prompt1.Enabled = false
				Prompt2.Enabled = false
				Prompt1e.Enabled = false
				Prompt2e.Enabled = false
				Accept:Play()
				Light1.BrickColor = BrickColor.new("Lime green")
				Light2.BrickColor = BrickColor.new("Lime green")
				Sound:Play()
				TClose:Play()
				wait(1)
				Light1.Color = Color3.new(0.372549, 0.368627, 0.368627)
				Light2.Color = Color3.new(0.372549, 0.368627, 0.368627)
				Bool.Value = false
				CountBool.Value = false
				Prompt1.Enabled = true
				Prompt2.Enabled = true
				Prompt1e.Enabled = true
				Prompt2e.Enabled = true
			else
				if Bool.Value == false then
					CountBool.Value = true
					Prompt1.Enabled = false
					Prompt2.Enabled = false
					Prompt1e.Enabled = false
					Prompt2e.Enabled = false
					Accept:Play()
					Light1.BrickColor = BrickColor.new("Lime green")
					Light2.BrickColor = BrickColor.new("Lime green")
					Sound:Play()
					TOpen:Play()
					wait(1)
					Light1.Color = Color3.new(0.372549, 0.368627, 0.368627)
					Light2.Color = Color3.new(0.372549, 0.368627, 0.368627)
					Bool.Value = true
					CountBool.Value = false
					Prompt1.Enabled = true
					Prompt2.Enabled = true
					Prompt1e.Enabled = true
					Prompt2e.Enabled = true
				end
			end
		elseif table.find(PH, item.Name) then
			CountBool.Value = true
			Prompt1.Enabled = false
			Prompt2.Enabled = false
			Prompt1e.Enabled = false
			Prompt2e.Enabled = false
			Light1.BrickColor = BrickColor.new("Really red")
			Light2.BrickColor = BrickColor.new("Really red")
			Refuse:Play()
			wait(1)
			Light1.Color = Color3.new(0.372549, 0.368627, 0.368627)
			Light2.Color = Color3.new(0.372549, 0.368627, 0.368627)
			CountBool.Value = false
			Prompt1.Enabled = true
			Prompt2.Enabled = true
			Prompt1e.Enabled = true
			Prompt2e.Enabled = true
		end
	end
end

function GateModule.HackInspection(Refuse,CountBool,Prompt1,Prompt2,Prompt1e,Prompt2e,Accept,Light1,Light2,Sound,TOpen,Bool,TClose)
	local Character = Player.Character
	for _, item in pairs(Character:GetDescendants()) do
		if table.find(HackClearance, item.Name) then
			if Bool.Value == true then
				CountBool.Value = true
				Prompt1.Enabled = false
				Prompt2.Enabled = false
				Prompt1e.Enabled = false
				Prompt2e.Enabled = false
				Accept:Play()
				Light1.BrickColor = BrickColor.new("Lime green")
				Light2.BrickColor = BrickColor.new("Lime green")
				Sound:Play()
				TClose:Play()
				wait(1)
				Light1.Color = Color3.new(0.372549, 0.368627, 0.368627)
				Light2.Color = Color3.new(0.372549, 0.368627, 0.368627)
				Bool.Value = false
				CountBool.Value = false
				Prompt1.Enabled = true
				Prompt2.Enabled = true
				Prompt1e.Enabled = true
				Prompt2e.Enabled = true
			else
				if Bool.Value == false then
					CountBool.Value = true
					Prompt1.Enabled = false
					Prompt2.Enabled = false
					Prompt1e.Enabled = false
					Prompt2e.Enabled = false
					Accept:Play()
					Light1.BrickColor = BrickColor.new("Lime green")
					Light2.BrickColor = BrickColor.new("Lime green")
					Sound:Play()
					TOpen:Play()
					wait(1)
					Light1.Color = Color3.new(0.372549, 0.368627, 0.368627)
					Light2.Color = Color3.new(0.372549, 0.368627, 0.368627)
					Bool.Value = true
					CountBool.Value = false
					Prompt1.Enabled = true
					Prompt2.Enabled = true
					Prompt1e.Enabled = true
					Prompt2e.Enabled = true
				end
			end
		elseif table.find(PH, item.Name) then
			CountBool.Value = true
			Prompt1.Enabled = false
			Prompt2.Enabled = false
			Prompt1e.Enabled = false
			Prompt2e.Enabled = false
			Light1.BrickColor = BrickColor.new("Really red")
			Light2.BrickColor = BrickColor.new("Really red")
			Refuse:Play()
			wait(1)
			Light1.Color = Color3.new(0.372549, 0.368627, 0.368627)
			Light2.Color = Color3.new(0.372549, 0.368627, 0.368627)
			CountBool.Value = false
			Prompt1.Enabled = true
			Prompt2.Enabled = true
			Prompt1e.Enabled = true
			Prompt2e.Enabled = true
		end
	end
end

return GateModule

Why are you letting the client handle events?

My first example was from an Server Script, then recommended to an module script, and I though it was an good idea and plus it would be more optimized aswell.

Plus, I need it to be server script so all players see the gate opening.

You shouldn’t let the client tell the server what to do, thats very insecure and easy to exploit. Everything in your client script can be moved over to the server script with almost no changes, which would make your code almost 100% more secure, and its also just easier to keep track of things that are all in one script

2 Likes

I mean, that’s true but it wouldn’t be an huge deal as this is just about doors. I wouldn’t believe some would try cheat just to open a door. More rare as this will go for an certain community which it will be small.

The issue that I’m having with both server script is about character which I need it so I know what player is holding.

Just sending a remote isn’t going stop hackers if the scripts are all on the workspace.
You set off the remote and then have a script in ServerScriptService pick it up with the …
HackEvent.OnServerEvent:Connect(function()

Hackers can not get into that folder and that is the whole point of sending a remote.

Also I see a lot of Color3.new(0.372549, 0.368627, 0.368627) not that, that is wrong but it’s much easier to understand and work with in RGB format.

color = Color3.new(0.372549, 0.368627, 0.368627)
color = Color3.fromRGB(95, 94, 94) – same thing. Red, Green, Blue … from 0 to 255

1 Like

Yeah, these events are when the player open the gate, the normal event with the normal cards while the hack event is for an hack tool given to enemies to open gates (which takes more time). I understand that isn’t gonna stop hackers but still, as this will be for an close small community, it wouldn’t be an problem.

And thank also for your hint about the RGB, it kinda gives same vibe but more easier.

Oh “hackers” are in the game as players … lol, that make more sense now.
You got sending remotes down (gratz) pick them up in ServerScriptService to stop real hackers.

side note: you can tell by the way you’re pushing everything here willing to raw code it out you’ll be really good someday. Keep it up, it’s in you.

1 Like

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