Is creating server scripts in StarterGui bad?

Server scripts will run anywhere the server has access to, but they will only run on the server-side, and the server script replicated to the client will sit there like a text file.

Yes, but the goal of why I’m doing this is to remove server check since it already in the server and by having the server script in StarterGui. Allows you to have the “LocalPlayer”, whenever I need to get data from the client I already have the “Player” so I can just fire from the server to client.

1 Like

Totally agree.

Also, it’s important to mention that -

When doing sanity checks, DONT try to prevent the exploiter from doing what hes doing. That won’t help you. They’ll always find their sneaky ways.
Focus mainly on making them impenetrable, meaning - if there’s an item that costs 100 Cash, don’t let them get it if they have insufficient amount.

You’re going to end up having to do it regardless, I promise you that. Try it out yourself and you’ll see what we all mean.

And if it’s on the server anyways just do what @Nerbzzz initially mentioned with PlayerAdded in a script inside of ServerScriptService.

1 Like

Could you not just

local SomePlayer = Players.LearningBasic

?

The client should not be able to send arguments over remotes that give them an advantage, simple as that.

Also, it’s important to not manage your UI’s from a server script. It’s better to use remotes [when needed, such as shops,quests,etc].

How would you know who the player is. That is what LocalPlayer is and the reason why I place my server scripts in StarterGui.

playeradded will do the trick :slight_smile:

EDIT: Sorry if it’s “annoying” it’s just the answer is right there…?

1 Like

Going back to the example you were already given:

local Players = game:GetService("Players") -- The players service. 

Players.PlayerAdded:Connect(function(Player) -- This passes the player instance as "Player"
   -- Do whatever you need to do with the player here instead of doing FindFirstAncestorOfClass('Player')
end)
1 Like

It could be in a loop? Maybe it could be saved as a string? I didn’t give you code that you were supposed to use, it was an example.

local PlayersList = {}

for _, Player in pairs(Players:GetPlayers()) do
    --Boom, you can now refer to a player.
    table.insert(PlayersList, Player.Name)
end

for _, PlayerName in pairs(PlayerList) do
    --You can refer to a player by doing this as well
    local Player = Players[PlayerName]
end

Or, with remotes:

RemoteEvent.OnServerEvent:Connect(function(Player)
    --Player is sent automatically as the first argument
    --As far as I know, exploiters can't spoof the first argument
    --As I explained before, maybe the server checks the IP and infers the player through that
end)

Yes, that’s actually a good substitute. Honestly I’m just thinking to much about it.

2 Likes

It’s not a “subsitute” its the first thing you should’ve thought about, It’s a ROBLOX service - And it’s way less hacky than what you are trying to do, Keeps everything clean because it’s a singular script, Therefore i recommend you just try playeradded and when it doesn’t work how you want THEN you can try a diffrent method. please i just want this discussion of odd methods to end

1 Like

I appreciate the help, that will be what I am adjusting to. Thank you