Detect if server or client?

I want to be able to detect if a PRINT is called on the server or the client. In the output, this is showed by green and blue colors. And a “- client” after it. I want to be able to get a string or something that allows me to see if the print happens on client.

I am using LogService for this but I haven’t found a way to do it. Unless there isn’t a way to do this. :man_shrugging:

2 Likes

game:GetService(“RunService”):IsServer() or IsClient()

9 Likes

just check to see if game.Players.LocalPlayer exists

there now you can see which side it is on

1 Like

But the logservice script is server sided right? How would that work? @D0RYU there is a way to switch between server and local… image I don’t think it would work that way.

1 Like

I don’t really get your problem sorry :D.

You can run both of those serversided or clientsided.

Example

local RunService = game:GetService("RunService") 
local DecideSide = RunService:IsServer() and "Server" or RunService:IsClient() and "Client"

print(DecideSide) 

@creepersaur

3 Likes

what are you talking about, this point has nothing to do with what I just said

game.Players.LocalPlayer is nil on a server script but it isn’t nil on a local script, honestly I don’t see why you can’t use what @caviarbro suggested

2 Likes

As I said, it won’t work. For some reason. The script that detects the Log output is on the server. I tested your localPlayer script and it kept saying server even on the client. Same goes for @caviarbro’s idea…

I tested both of them and they worked

--SERVER
print(game:GetService("RunService"):IsServer() and "Server" or "Client")
print(game.Players.LocalPlayer == nil and "Server" or "Client")
--CLIENT
print(game:GetService("RunService"):IsServer() and "Server" or "Client")
print(game.Players.LocalPlayer == nil and "Server" or "Client")

image

these methods obviously work

Can you please show us your code and the output will help a lot :).

Ok, you are probably not getting this correctly. You know how you separated and put the same scripts in a local script and a server script? I only use one script. Not two. And I am trying to detect using LogService. Which I don’t think works.

wait do you want to see if the studio camera is in server or client?

1 Like

Pretty much. But image (not my photo) It shows that the message was printed using the local and server with colors and stuff I wanted to see if LogService could detect that.