Finding a Player through an ObjectValue

local db = true

local Player = script.Parent.Parent.Player
print(Player.Name)

while true do
	wait()
	if script.Parent and script.Parent.Position.Y > 6.01 and db == true then
		db = false
		game:GetService("ReplicatedStorage").Events.Message:FireClient(Player, "Tycoon spawned too high.", "Red")
		script.Parent.Parent:Destroy()
	end
		
	if script.Parent and script.Parent.Position.Y < 5.99 and db == true then
		db = false
		game:GetService("ReplicatedStorage").Events.Message:FireClient(Player, "Tycoon spawned too low.", "Red")
		script.Parent.Parent:Destroy()
	end
end

Sorry, what I meant was how you’re defining the ObjectValue, not the player variable.

That doesn’t answer this question

oh,

local Tycoon = nil
Tycoon = game.ReplicatedStorage.Tycoon:Clone()
Tycoon.Parent = workspace.Tycoons
Tycoon.Name = Player.Name .. "'s Tycoon"
Tycoon.Player.Value = Player
Tycoon.Ball.BillboardGui.PlayerName.Text = Player.Name .. "'s Tycoon"

(this is not the entire code)

the player that owns the tycoon

What is Player? can we see where u define the Player variable?

Have you checked if:

Tycoon.Name = Player.Name .. "'s Tycoon"
Tycoon.Player.Value = Player

actually returns the Player.Name and if Tycoon.Player.Value is actually the player? you can check in this own script.

yes it does actually return it.

local function SpawnTycoon(Player)

1 Like

Is the first code (The player nil one) running after that Tycoon code is ran? There could be a chance It didn’t actually edit the ObjectValue yet.

RIGHT, you’re right ill try it out

you are correct but when i try to wait until the value isnt nil it just waits infinitely @Isaque232

local db = true
local Player = (script.Parent.Parent.Player.Value)

repeat wait() until Player == not nil -- waits here forever

You are checking it the wrong way, since you’ve already defined the Player variable, and It will be nil forever because of that.

Instead you can just do this:

local db = true

repeat wait() until script.Parent.Parent.Player.Value

Which will keep checking if the actual value is not nil.

1 Like