Getting the player from an ObjectValue?

Hey,

I want to get the player from a ObjectValue but it doesn’t work.

local Settings = require(script.Parent.Parent.Parent.Parent.Parent.Parent.Settings)
local Frame1 = script.Parent.BillboardGui.Frame
local Frame2 = Frame1.Frame
local Text = Frame2.Text
local TextLabel1 = script.Parent.BillboardGui.Text
local uiGradient1 = script.Parent.BillboardGui.Frame.Frame.UIGradient
local cost = script.Parent.Parent.Price

local player = script.Parent.Parent.Parent.Parent:FindFirstChild("Owner").Value.Name

while wait() do
	print(player)
	Text.TextTransparency = script.Parent.Transparency
	TextLabel1.TextTransparency = script.Parent.Transparency
	Frame1.BackgroundTransparency = script.Parent.Transparency
	Frame2.BackgroundTransparency = script.Parent.Transparency
	TextLabel1.Text = script.Parent.Parent.Name
	if not script.Parent.Parent.Parent.Parent.PurchasedObjects:FindFirstChild("Store") then
		script.Parent.Parent.Price.Value = 9999999999
		Frame2.Text.Text = "🔒LOCKED"
	elseif  script.Parent.Parent.Parent.Parent.PurchasedObjects:FindFirstChild("Store") then
		game:GetService("ReplicatedStorage").UnlockedBasement:FireClient(player)
		script.Parent.Parent.Price.Value = 35000
		Frame2.Text.Text = "$".. Settings:ConvertComma(cost.Value)
	end
	
	if script.Parent.Transparency ==1 then 
		uiGradient1.Enabled = false
	else
		uiGradient1.Enabled = true
	end
	
end

The FireClient isn’t working because i can’t define the player.

Error:

my guy use a “game.Players.LocalPlayer” it’s more easier and make some readjusting so the script does not entirely break or mix up when the player respawns also enclose the variabled object in a tostring like this

tostring(game.Players.LocalPlayer:FindFirstChild("Owner").Value.Name)

also add a if statement so the loop function does not start without checking if the specific player is not the assumed owner

It’s a serverscript so I can’t use localplayer lol

Why? Whats the sense of that? Why cant I just make it a normal variable lol

basically your specifically referring a string type of value which is one of the cases in this incorrection, for the other previous message as your curious confusion in using a localized var, you can also try using a for function (a function that loops through every player accumulated in the server count or players object below lighting in the explorer)

when a for function has checked if a player matching the similar detail of said conditions then you may set it to that player’s, since you kinda look like you’re a beginner and using some community modules i’ll introduce you in a single sentence how for functions work

local player -- an empty variable or called a global variable to be filled later

for i, v in pairs(game.Players:GetPlayers()) do --a repeating procss
  if v ~= nil and v.UserId == game.OwnerId then --checks if the players userID is exact to the games ownerId, use v.IsInGroup(game.OwnerId) instead if its a group game
    player = v -- this sets the variable to the player itself
  end
end

or you can try another approach

1 Like

i think the way ur handling getting the player is wrong. The script is only going to get one person at the player

local player = script.Parent.Parent.Parent.Parent:FindFirstChild("Owner").Value.Name

--If you want to get the player you can only do so using events or if you want to apply an affect to everyone u  technically could do
local players = game:GetService("Players")

for _,plr in ipairs(players:GetPlayers()) do

         -- Whatever u want to do with script

end

Yes, only one person thats correct. I only want it to be one person because the script will be duplicated.
But I don’t know why its not accepting the objectvalue.

Where do I get the ownerid from?
Why should I check if someone is in the group? I don’t want them to join the group

then ur scripting has me very confused. Why not use a local script? how do you detrmine the specific player with duplicated serverscripts? duplicating server scripts is going to be very laggy

Because its not working with the tycoon kit.

Every team has a Owner value and i will put the script inside every team.

Try this:


local Settings = require(script.Parent.Parent.Parent.Parent.Parent.Parent.Settings)
local Frame1 = script.Parent.BillboardGui.Frame
local Frame2 = Frame1.Frame
local Text = Frame2.Text
local TextLabel1 = script.Parent.BillboardGui.Text
local uiGradient1 = script.Parent.BillboardGui.Frame.Frame.UIGradient
local cost = script.Parent.Parent.Price

local player = script.Parent.Parent.Parent.Parent:FindFirstChild("Owner").Value

while wait() do
	print(player)
	Text.TextTransparency = script.Parent.Transparency
	TextLabel1.TextTransparency = script.Parent.Transparency
	Frame1.BackgroundTransparency = script.Parent.Transparency
	Frame2.BackgroundTransparency = script.Parent.Transparency
	TextLabel1.Text = script.Parent.Parent.Name
	if not script.Parent.Parent.Parent.Parent.PurchasedObjects:FindFirstChild("Store") then
		script.Parent.Parent.Price.Value = 9999999999
		Frame2.Text.Text = "🔒LOCKED"
	elseif  script.Parent.Parent.Parent.Parent.PurchasedObjects:FindFirstChild("Store") then
		game:GetService("ReplicatedStorage").UnlockedBasement:FireClient(player)
		script.Parent.Parent.Price.Value = 35000
		Frame2.Text.Text = "$".. Settings:ConvertComma(cost.Value)
	end
	
	if script.Parent.Transparency ==1 then 
		uiGradient1.Enabled = false
	else
		uiGradient1.Enabled = true
	end
	
end

it’s automatically confirmed that if a dev is involved within a group game, they’ll be in the group that created or owns the game which you’re just trying to determine if the people will permission to the game will be able to access this (this is specifically optional for dev specs)

the ownerID is always returned from the game, you can write print(game.OwnerId) and it’ll print the ID of the creator’s to prevent probably issues when people change their username from either 1000 robux fee or a staff supported revert.

1 Like

And if your using the player string do this, im sorry for l8e response ( there might be a typo here) id still reccomend using playerid though

local Settings = require(script.Parent.Parent.Parent.Parent.Parent.Parent.Settings)
local Frame1 = script.Parent.BillboardGui.Frame
local Frame2 = Frame1.Frame
local Text = Frame2.Text
local TextLabel1 = script.Parent.BillboardGui.Text
local uiGradient1 = script.Parent.BillboardGui.Frame.Frame.UIGradient
local cost = script.Parent.Parent.Price

local playerName = script.Parent.Parent.Parent.Parent:FindFirstChild("Owner").Value.Name
local players = game:GetService("Players")

local function getPlayerFromName(Name) do
	for _,player in pairs(players:GetPlayers())	 do
		if player.Name == player then
			return player
		end
	end
end
local player = getPlayerFromName("PlayerName")
while wait() do
	print(player)
	Text.TextTransparency = script.Parent.Transparency
	TextLabel1.TextTransparency = script.Parent.Transparency
	Frame1.BackgroundTransparency = script.Parent.Transparency
	Frame2.BackgroundTransparency = script.Parent.Transparency
	TextLabel1.Text = script.Parent.Parent.Name
	if not script.Parent.Parent.Parent.Parent.PurchasedObjects:FindFirstChild("Store") then
		script.Parent.Parent.Price.Value = 9999999999
		Frame2.Text.Text = "🔒LOCKED"
	elseif  script.Parent.Parent.Parent.Parent.PurchasedObjects:FindFirstChild("Store") then
		game:GetService("ReplicatedStorage").UnlockedBasement:FireClient(player)
		script.Parent.Parent.Price.Value = 35000
		Frame2.Text.Text = "$".. Settings:ConvertComma(cost.Value)
	end
	
	if script.Parent.Transparency ==1 then 
		uiGradient1.Enabled = false
	else
		uiGradient1.Enabled = true
	end
	
end