Adding Security On Local Scripts

Hello,

So I am creating a script thing and it uses local scripts. I have the issue that I don’t want any exploiters to be able to view the local script stuff so I used a remote function to try to add some security in. I have never used them before and getting a erorr so I am not sure how I could fix it.

Server Script:

local RS = game:GetService("ReplicatedStorage")
RS.EpicOne.OnServerEvent:Connect(function() 
	local player = game:GetService("Players")
	--Links to the "Removes all of the first part"
	local BackDrop = player.LocalPlayer.PlayerGui["Start UI"].BackDrop
	local Image = player.LocalPlayer.PlayerGui["Start UI"].LighthouseLogo
	local TextButton = player.LocalPlayer.PlayerGui["Start UI"].ClickThingFirst
	local TextForButton = player.LocalPlayer.PlayerGui["Start UI"].ClickThingFirstBack
	local TraieeQuizText = player.LocalPlayer.PlayerGui["Start UI"].TraineeQuiz
	local WhoCreated = player.LocalPlayer.PlayerGui["Start UI"].CreatedByLifeDigger
	--Links to the "Adds in the second part
		-- Removes all of the first part
		BackDrop.Visible = false
		Image.Visible = false
		TextButton.Visible = false
		TextForButton.Visible = false
		TraieeQuizText.Visible = false
		WhoCreated.Visible = false
		-- Adds in the second part
end)

Local Script:

local RS = game:GetService("ReplicatedStorage") 
script.Parent.MouseButton1Click:Connect(function() 
	RS.EpicOne:FireServer()
end)

Error:

image

You can’t use LocalPlayer in a serverscript. First argument of .OnServerEvent is player that fired the event.

How would I do this then??? Now thinking about it I feel abit stupid.

see, i already told you. That means it’s the LocalPlayer

A couple of things to note:

  • Like what Atom said, you can’t use LocalPlayer in a serverscript. A remote event to the server passes the player variable automatically, so you can use that instead. See this article for more information.
  • ALWAYS assume that the client is compromised. Manipulating the UI from the server side on a regular basis is generally frowned upon because it takes up processing power and isn’t particularly effective in stopping cheaters. There is usually a better solution to check for suspicious behavior.

Wait I don’t understand. Is that not what I did??? (I understand it’s not the best to do from the server side but it’s not a massive bit in it and only for one person).

No. When we say that it’s an argument from the function, that means that it is given to you from the function, not anywhere else.

So a proper use would be

RS.EpicOne.OnServerEvent:Connect(function(player)

Notice the “player” in between the parenthesis in the function?

So like the bellow? I am still getting the same error.

image

When you’re receiving the event, you reference the player’s playerGui, not the local playerGui.

So this line: player.LocalPlayer.PlayerGui would become player.PlayerGui
Also, when you’re calling fireserver, I’m pretty sure the player is always passed, so I don’t believe you need that player argument on the client.

Finally, It’s best to handle gui inputs and etc on the client, instead of accessing the PlayerGui. This is due to client/server boundary not replicating for some input functions, e.g textbutton. While, I understand you’re trying to reduce the chances of exploiting, you shouldn’t use the server entirely for your game. There are some things such as Gui input, etc that should be handled on the client. Just have the appropriate sanity checks.

I fixed your code this should work let me know if it doesent

Server Script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Remote = ReplicatedStorage.EpicOne

Remote.OnServerEvent:Connect(function(Player)
	local PlayerGui = Player:WaitForChild("PlayerGui")
	local StarterUI = PlayerGui:WaitForChild("Start UI")
	local BackDrop = StarterUI:WaitForChild("BackDrop")
	local Image = StarterUI:WaitForChild("LighthouseLogo")
	local TextButton = StarterUI:WaitForChild("ClickThingFirst")
	local TextForButton = StarterUI:WaitForChild("ClickThingFirstBack")
	local TraieeQuizText = StarterUI:WaitForChild("TraineeQuiz")
	local WhoCreated = StarterUI:WaitForChild("CreatedByLifeDigger")
	
	BackDrop.Visible = false
	Image.Visible = false
	TextButton.Visible = false
	TextForButton.Visible = false
	TraieeQuizText.Visible = false
	WhoCreated.Visible = false
end)

Local Script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Remote = ReplicatedStorage.EpicOne
local Button = script.Parent
Button.MouseButton1Click:Connect(function()
	Remote:FireServer()
end)

if you put the “player” paramiter in the event fire thing itll get the player when the remote is fired

1 Like

I am getting a error here.

Also on the other bit.

Sorry I had misformatted it it should be fixed now “devforum needs code boxes to work correctly and not ittalicisize it”.

I wouldn’t do this at all there is no use it doing it as the code does not contain anything that a exploiter could not do without this Script.

Yea I know right now there is not but I will be adding some stuff that can mess some things up.