I have the player’s name already stored in a StringValue named “Owner”. I’m trying to find the player by finding if “Players” has a child with the corresponding name. I’m doing this so I can send a :FireClient() across.
local Health = script.Parent.Health
local Remote = script.Parent.HealthChanged
local OwnerName = script.Parent.Owner.Value
local Players = game:GetService("Players")
local Player = Players:FindFirstChild(OwnerName)
Health.Changed:Connect(function(Value)
print("Health Changed to "..Value.."/100")
Remote:FireClient(Player, Value)
end)
Since you’re changing the value after you first set it as a variable, your variable always stores the original value. local OwnerName = script.Parent.Owner.Value doesn’t update when the value of owner updates. If you want it to update, you’d need to do something like local Owner = script.Parent.Owner and look for a player (players:FindFirstChild(Owner.Value)) every time you want to fire.
You should also check if the player exists before firing the event so it doesn’t error like that. You can just do something simple like
if Player then
Remote:FireClient(Player, Value)
end
I’ve changed the default value of Owner to “Owner” and I tried to find if the value was changed
local Owner = script.Parent.Owner
local OwnerName = Owner.Value
if OwnerName == "Owner" then
print("Empty Value")
Owner.Changed:Connect(function(Name)
OwnerName = Name
end)
end
Instead of using ValueObjects, couldn’t you just use a ModuleScript to store this information? It avoids the cost of instances in the DataModel and makes modification fairly quick.