Control multiple scripts

“How can I design a modular, event-driven system or anything like this so that when a player enters a level, specific behaviors—like changing the camera angle and enabling click-to-move—are activated, and when the player leaves the level, these changes are reverted (restoring the normal camera and controls) without having to remove the local scripts entirely?”

1 Like

Hi @xxmanado

I made system that changes player’s client stats when part is touched based on attribute.

It’s a simple system, but if you want, I can script the entire thing for you since I’m feeling bored. Just let me know what you want to change!

Client Script - Place in StarterCharacterScripts or StarterPlayerScripts or StarterGui

local Players = game:GetService("Players")

local Player = Players.LocalPlayer

local Char = Player.Character or Player.CharacterAdded:Wait()
local Camera = workspace.CurrentCamera

local CharacterParts = {}

function DoSomething(Name,Value)
	
	if Name == "FieldOfView" then
		Camera.FieldOfView = Value
	end
	
end

local LastTouched = nil


for _,Child in pairs(Char:GetChildren()) do
	if Child:IsA("BasePart") then
		table.insert(CharacterParts,Child)
		
		Child.Touched:Connect(function(otherPart)
			
			if not CharacterParts[otherPart] and otherPart:HasTag("ControlPoint") and LastTouched ~= otherPart then
				LastTouched = otherPart
				
				for Name,Value in pairs(otherPart:GetAttributes()) do
					DoSomething(Name,Value)
				end
			end
		end)
		
	end
end

Here is my screen:

Notes:

  1. You must tag the parts with the tag “ControlPoint.”
  2. Add attributes to each part.
  3. I tested it, and it works, but if it doesn’t work when you test it, it means you forgot something.
2 Likes

thanks but…

why didbu send it to me ? it diesnt answer the quesiob

1 Like

if you add boolean attribute like EnableCustcene
to play cutscene when enter new level to detect this you need part and when its touched then it apply changes:

like this:

elseif Name == "EnableCutscene" then
	if Value then
		PlayCutscene()
    end
end
1 Like

u still dont understand what i want

to keep it simple. lets talk about camera scriptable type in order to make follow the player for specific actions u need runservice
now when a player lets say he finishes these actions
how can i make the script stop (like by deleting it or what) i dont want to put the connection in a variable becausw the whole script is just about camera so i’d rather find a way to fully stop it

2 Likes

hello,
would a debounce not be fit for what you are doing?
as in you would have a variable (e.g named “Running”) which is set to true or false depending on whether or not you want the script running, and then make the RunService event check if Running is true or false, making it start/continue running or stop running respectively.

edit: sorry, i thought you already had a camera script set up and were wondering how to stop and start it.

1 Like

Oh now makes sense:

Using Module Script its easy to stop,Optimazed and organized

local RunService = game:GetService("RunService")

local Camera = workspace.CurrentCamera

local module = {}

local Connection = nil

function module.StartCustomCamera()
	
	Connection = RunService.RenderStepped:Connect(function(DeltaTime)
		
	end)
end

function module.StopCustomCamera()
	
	if Connection then
		Connection:Disconnect()
		Connection = nil
	end
end

return module

can u give me brief example pls i think i am starting to get it

Here is my setup:

Red part named Event Changer has attribute CustomCamera as you can see its Disabled.

Green part also named Event Changer has attrobute Custom Camera and its Enabled.

you can do

local Players = game:GetService("Players")

local Player = Players.LocalPlayer

local Char = Player.Character or Player.CharacterAdded:Wait()
local Camera = workspace.CurrentCamera

local CharacterParts = {}

local CustomCamera = require(script:FindFirstChild("CustomCamera"))

function DoSomething(Name,Value)
	
	if Name == "FieldOfView" then
		Camera.FieldOfView = Value
	elseif Name == "CustomCamera" then
		
		if Value then
			CustomCamera.StartCustomCamera()
		else
			CustomCamera.StopCustomCamera()
		end
	end
	
end

local LastTouched = nil

for _,Child in pairs(Char:GetChildren()) do
	if Child:IsA("BasePart") then
		table.insert(CharacterParts,Child)
		
		Child.Touched:Connect(function(otherPart)
			
			if not CharacterParts[otherPart] and otherPart:HasTag("ControlPoint") and LastTouched ~= otherPart then
				LastTouched = otherPart
				
				for Name,Value in pairs(otherPart:GetAttributes()) do
					DoSomething(Name,Value)
				end
			end
		end)
		
	end
end

Module Script: -right now it does nothing you need to modify it

local RunService = game:GetService("RunService")

local Camera = workspace.CurrentCamera

local module = {}

local Connection = nil

function module.StartCustomCamera()
	
	Connection = RunService.RenderStepped:Connect(function(DeltaTime)
		
	end)
end

function module.StopCustomCamera()
	
	if Connection then
		Connection:Disconnect()
		Connection = nil
	end
end

return module

image

By the way, it’s a simple method, but there’s a other more complicated ways to do it.

i Rewrote Module here is demo:

New Module:

local RunService = game:GetService("RunService")
local Players = game:GetService("Players")

local Player = Players.LocalPlayer

local Char = Player.Character or Player.CharacterAdded:Wait()
local Camera = workspace.CurrentCamera

local HumanoidRootPart:Part = Char:FindFirstChild("HumanoidRootPart")

local module = {}

local Connection = nil

function module.StartCustomCamera()
	Camera.CameraType = Enum.CameraType.Scriptable
	
	Connection = RunService.RenderStepped:Connect(function(DeltaTime)
		Camera.CFrame = HumanoidRootPart.CFrame + HumanoidRootPart.CFrame.LookVector * -10 + Vector3.new(0,5,0)
	end)
end

function module.StopCustomCamera()
	
	if Connection then
		Camera.CameraType = Enum.CameraType.Custom
		
		Connection:Disconnect()
		Connection = nil
	end
end

return module

Video

1 Like

thanks bro but couldnt the hacker bypass this easily?

1 Like

Camera settings can only be changed by a LocalScript, so it doesn’t matter if a hacker can modify them also they cannot change Camera settings for all players only themself. Hackers can simply inject their own scripts, making an anti-cheat for this pointless.

Even if they use that, it won’t make much of a difference as long as they don’t manipulate progress, such as DataStores or stats. Using the camera, like Freecam, doesn’t give them an actual advantage—it only lets them expose your map, such as the location of hidden buildings.

This kind of exploit can’t be detected or prevented with an anti-cheat.

For example, speed hacks can be countered with an anti-cheat because server scripts can calculate:

speed = distance / time -- Usually calculated per second to check if the walk speed is abnormal. If it is, the player is stopped.

Quote from xxmanado:

“Couldn’t the hacker bypass this easily?”

Answer: Yes.

Here’s how to prevent a major disadvantage:

When a player fires an event for winning, check if the part’s distance from the player is actually close. If not, stop the event to prevent teleport hacks. Additionally, set all relevant parts’ NetworkOwnership to nil .
Make sure to safely protect RemoteEvents because if client controls server it may cause huge damage to your game.

If you don’t fully understand what I mean or don’t know how to protect the game, you can check out this video by GnomeCode. He has a great tutorial on preventing hackers from cheating.

1 Like

i do understand and i ve watched this video before
but isnt there really a way to stop the hacker from changeing his cam?? and cant i detect (which probably cant) if the hacker changes his cam position ?