How To Get The Owner Of An Experience

Hi, I need help, I want to create a GUI that shows only if you’re the Owner of an experience, I don’t have anything setup right now, I don’t need the full script, I only need to know how to get the Owner of the Experience, thanks in advance :smiley:

2 Likes

One thing you can do is just do game.CreatorId and that’ll return the owners user ID, and then you can check the player’s user ID to see if it’s the same.

3 Likes

Ok, thanks! Gonna try thsi method! Also I didn’t know taht game.CreatorId even existed :rofl::rofl::rofl:

Also, sorry I forgot to say this, but how do you get the PlayerId? Sorry for the late reply I forgot to ask

player.UserId returns their user id.

1 Like

You can access a Player’s id directly by using Player.UserId as @Katrist said.

Also, here’s what I found about the Player class:
https://create.roblox.com/docs/reference/engine/classes/Player

1 Like

Sorry but it doesn’t work, I’m doing it in Studio, i published the game, I am the owner but it says that I’m not the owner, here’s the script

local button = script.Parent
local uis = game:GetService(“UserInputService”)
local localplayer = game:GetService(“Players”).LocalPlayer
local playerid = localplayer.UserId

button.MouseButton1Click:Connect(function()
if playerid == game.CreatorId then
print(“Clicker is the Owner”)
else
print(“Clicker is not the Owner”)
end
end)

The game is not under a group, but it still outputs Clicker is not the Owner, In Studio I have my avatar, so I don’t know what’s the problem
Note: If you need the gerarchy then it’s in StarterGui, there’s a ScreenGui, there’s under it a TextButton and under it there’s the LocalPlayer

Just tried it myself and it seems game.CreatorId actually prints 0 when printed in-game
What I would recommend is using the MarketplaceService on the game.PlaceId, and get the creator that way:

local button = script.Parent
local uis = game:GetService("UserInputService")
local marketplaceService = game:GetService("MarketplaceService")
local localplayer = game:GetService("Players").LocalPlayer
local playerid = localplayer.UserId

button.MouseButton1Click:Connect(function()
     if game.PlaceId == 0 then print("Place isn't published") return end

     local product = marketplaceService:GetProductInfo(game.PlaceId, Enum.InfoType.Asset)
     if product.Creator.CreatorTargetId == playerid then
          print("Clicker is the Owner")
     else
          print("Clicker is not the Owner")
     end
end)
1 Like

If its 0, that means there is no owner. which It could mean the game is unpublished.

I tested with my games

A Unpublished game prints 0

A Published game prints my UserId which is 3625422122

1 Like

I have published my game and the game.CreatorId still prints as 0

odd.

works alright for me.

Thanks, now it prints “clicker is the Owner”, now I’m gonna check if it works fo non-Owners
Edit: How would I be able to play as Player? I don’t know how

Make sure to mark as a solution if it worked for you

To play as a misc player you can go to the Test tab, and start a 1 player local server

image

Yes but the it says that the place isn’t published so I will have to add some way from the published place, but because everything else I have is mobile and I can’t change account I will have to change the scrip, if ti works I will make sur two mark your answer as the solution :grin:

Hi, I had to modify the script by a little, and there’s a problem, now if I click the button, it prints “Clicker is the Owner” but also “Clicker is not the Owner”, the script is:

local button = script.Parent
local uis = game:GetService("UserInputService")
local marketplaceService = game:GetService("MarketplaceService")
local localplayer = game:GetService("Players").LocalPlayer
local playerid = localplayer.UserId
local frame = button.Parent.ServerFrame

local product = marketplaceService:GetProductInfo(game.PlaceId, Enum.InfoType.Asset)
if product.Creator.CreatorTargetId == playerid then
	button.Visible = true
else button.Visible = false
	end
button.MouseButton1Click:Connect(function()
		if game.PlaceId == 0 then print("Place isn't published") return end
		print("Clicker is the Owner")
		if frame.Visible == true then
			frame.Visible = false
		else 
			frame.Visible = true
		end
		print("Clicker is not the Owner")
end)

If anybody can help than thanks!
Edit: Sorry, there was only a really little problem (also a little dumb) I still need to test for the non-Owner

I was able to solve the problems, your script works! Maked as solution

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