Private server owner free cam only

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve?
    I want only private server owner have the free cam feature

  2. What is the issue?
    My code isn’t working

  3. What solutions have you tried so far?
    already search on yt and other social medias but none results

local LocalPlayer = game.Players.LocalPlayer
local PlayerGui = LocalPlayer:WaitForChild("PlayerGui")

local freeCamGui = PlayerGui:WaitForChild("Freecam")

if not LocalPlayer.UserId == game.PrivateServerOwnerId then
	if PlayerGui then
		if freeCamGui then
			freeCamGui:Destroy()
		end
	end	
end

I don’t know this count as a error or not but i just gonna send

PrivateServerOwnerId cannot be checked on the client, please check on the server.
1 Like

Run a check on server script using Players.PlayerAdded event.

1 Like

use remotefunctions
check PrivateServerOwnerId on the server

1 Like

like this?

2 Likes

The issue is you’re running this in a LocalScript (running on the client), which doesn’t have permission to access the data.

You need to send a request for the information via RemoteEvent to the server to see if the player Is the server owner.

You can research remote events and client server communication on Roblox’s Developer Hub

1 Like

Like this? Sorry Im not too good on this stuffs

Local Script:

local RemoteEvent = game.ReplicatedStorage:WaitForChild("RemoteEvent")

game.Players.PlayerAdded:Connect(function(player)
	if not player.UserId == game.PrivateServerOwnerId then
		RemoteEvent:FireClient(player)
	end
end)

Server Script:

local Players = game:GetService("Players")
local RemoteEvent = game.ReplicatedStorage:WaitForChild("RemoteEvent")

RemoteEvent.OnServerEvent:Connect(function(player)
	local playerGui = player:WaitForChild("PlayerGui")
	local Freecam = playerGui:WaitForChild("Freecam")
	if playerGui then
		if Freecam then
			Freecam:Destroy()
		end
	end
end)

EDIT: already tested it but still doesnt work, and no errors appears on the output

Since i’m not good on those stuffs but can you show me how to do that?

You need to run the script in ServerScriptService, a.k.a on the server. You can use remote events/functions. in short, Remote events send info from client-server or server-client.

read more here:Bindable Events and Functions | Roblox Creator Documentation
I recommend you read roblox’s client-server model before proceeding: Client-Server Model | Roblox Creator Documentation

--script
game.ReplicatedStorage.RemoteFunction.OnInvoke = function(player)
    -- check things here
    return player.UserId == game.PrivateServerOwnerId
end
-- localscript
local isOwner = game.ReplicatedStorage.RemoteFunction:Invoke()

insert a RemoteFunction in ReplicatedStorage and name it RemoteFunction

– script
game.ReplicatedStorage.RemoteFunction.OnServerInvoke = function(player)
– check things here
return player.UserId == game.PrivateServerOwnerId
end

– local script

local isOwner = game.ReplicatedStorage.RemoteFunction:InvokeServer()

if isOwner then

– your function

end)