How to prevent scripts editing specific objects

Hi, my name is DarkMenacing

I was editing my game on roblox and i came to a problem.

Everytime i run this local script:

local TweenService = game:GetService("TweenService")
local SoundService = game:GetService("SoundService")
local StarterGui = game:GetService("StarterGui")
local Activated = true
local Info = TweenInfo.new(.2, Enum.EasingStyle.Sine, Enum.EasingDirection.In)

function MouseClick()
	if Activated == false then
		local Goal = {}
		Goal.BackgroundColor3 = Color3.new(1, 0, 0)
		local Tween1 = TweenService:Create(script.Parent.Parent, Info, Goal)
		
		SoundService.SFX.ClickingSound:Play()
		script.Parent:TweenPosition(UDim2.new(0.494, 0,0, 0), Enum.EasingDirection.In, Enum.EasingStyle.Sine, .2)
		Tween1:Play()
		for _,i in pairs(StarterGui:GetChildren()) do
			if i:IsA("Frame") or i:IsA("TextButton") then
				i.Material = Enum.Material.Metal
			end
		end
	else
		local Goal = {}
		Goal.BackgroundColor3 = Color3.new(0.333333, 1, 0)
		local Tween1 = TweenService:Create(script.Parent.Parent, Info, Goal)

		SoundService.SFX.ClickingSound:Play()
		script.Parent:TweenPosition(UDim2.new(0, 0,0, 0), Enum.EasingDirection.In, Enum.EasingStyle.Sine, .2)
		Tween1:Play()
	end
end

it always edit frames (like sliders) and buttons that i dont want, so how do i prevent this from happening?

Anything will help! - Darkmenacing

Your getting every frame or text button in StarterGui. To prevent this, you could use an if statement like so:

for _,i in pairs(StarterGui:GetChildren()) do
			if i:IsA("Frame") or i:IsA("TextButton") then
                           if i.Name == "guiname" or i.Name == "othergui" then
                              return
                           else
				i.Material = Enum.Material.Metal

edit: indentation might be wrong, edited your code on devforum only (have not tested)

but, how could i do the same thing but shorter? i saying that how could i do that but shorter to prevent in the future the script not be long

Not sure, you could use a module script for it; although I have only made 1 module script and that was from 10 other posts helping me on it xd. So I am not pretty good at module scripts. Actually, here I could try: Make another module script and in there do this:

local module = {

["guiname"],

["otherguiname"],

["so"],

["on"],

["and"],

["so"],

["forth"]

}

--indentation is weird idk why
return module

Then in the script your post is about you can access it like this

local data = require(modulename)

if i.Name == tostring(data[i.Name] then
                              return
                           else
--do stuff

So all in all, your code should look something like this:

local TweenService = game:GetService("TweenService")
local SoundService = game:GetService("SoundService")
local StarterGui = game:GetService("StarterGui")
local Activated = true
local Info = TweenInfo.new(.2, Enum.EasingStyle.Sine, Enum.EasingDirection.In)
local data = require(pathtomodule)

function MouseClick()
	if Activated == false then
		local Goal = {}
		Goal.BackgroundColor3 = Color3.new(1, 0, 0)
		local Tween1 = TweenService:Create(script.Parent.Parent, Info, Goal)
		
		SoundService.SFX.ClickingSound:Play()
		script.Parent:TweenPosition(UDim2.new(0.494, 0,0, 0), Enum.EasingDirection.In, Enum.EasingStyle.Sine, .2)
		Tween1:Play()
		for _,i in pairs(StarterGui:GetChildren()) do
			if i:IsA("Frame") or i:IsA("TextButton") then
--Make edit stand out
                           if i.Name = tostring(data[i.Name] then
                              return
                           else
				i.Material = Enum.Material.Metal
--Woahhh so cool edit 
			end
		end
	else
		local Goal = {}
		Goal.BackgroundColor3 = Color3.new(0.333333, 1, 0)
		local Tween1 = TweenService:Create(script.Parent.Parent, Info, Goal)

		SoundService.SFX.ClickingSound:Play()
		script.Parent:TweenPosition(UDim2.new(0, 0,0, 0), Enum.EasingDirection.In, Enum.EasingStyle.Sine, .2)
		Tween1:Play()
	end
end

This should work.

1 Like

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