Trouble getting player from object value

So at the moment, I’m trying to use GetPlayerFromCharacter to fire a client event. The issue: Whenever I use an objectvalue containing a character to get a player from that character, the “player” variable is always nil.

Code:
local On_Target = game:GetService(“ReplicatedStorage”):WaitForChild(“On_Target”)
local Ball = script.Parent
local Target = Ball:WaitForChild(“Target”)

Target.Changed:Connect(function()
local Character = Target.Value
print(Character)

local Player = game.Players:GetPlayerFromCharacter(Character)
print(Player)

On_Target:FireClient(Player)

end)

First of all, the Character value does actually print out the character. Also, the script is located in a part, which also houses the object value that contains the character.

1 Like

How are you changing the value of the ObjectValue? on touch? with a server script?
Can you show the script that is changing the ObjectValue? Maybe you are not providing the Model of the character.

local On_Target = game:GetService("ReplicatedStorage"):WaitForChild("On_Target")
local Ball = script.Parent
local Target = Ball:WaitForChild("Target")

Target.Changed:Connect(function(NewVal)
	warn(NewVal.ClassName, "==", "Model?") -- is really a model?
	local Player = game.Players:GetPlayerFromCharacter(NewVal)
	warn(Player)
	On_Target:FireClient(Player)
end)
1 Like

Thanks, It turned out that the object’s value was a player.

1 Like

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