Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Identifying ObjectValue in ServerStorage?

local Owner = script.Parent.Owner
game.ServerStorage.MoneyStorage.Owner.Value.Value =game.ServerStorage.MoneyStorage.Owner.Value.Value + hit.Cash.Value

The point of the script is to establish a variable named "Owner" and identify the ObjectValue which should have the name of a player.

Next, it will go through ServerStorage.MoneyStorage and find a NumberValue with the name of Owner, so if "carcanken" is the owner, it will look inside game.ServerStorage.MoneyStorage.carcanken.Value and access it.

When I try this, I receive the message that "Owner is not a valid member of MoneyStorage". I think this is due to me not knowing how to properly identify the Owner variable in this situation.

Any help would be appreciated, thanks!

1 answer

✓ Accepted answer

If I understand your question correctly, you want to search MoneyStorage for an object with the same name as the script's parent. As-is, your code is erroring because instead of searching by the name of the object stored in the variable Owner, it's instead searching for a child whose name is the string "Owner".

Why is that? Something.SomethingElse is syntactic sugar for Something['SomethingElse']. You're searching for a child with the same name as the string you put following the period. Instead, you'll want to try something like this:

local OwnerName = script.Parent.Owner.Value.Name
local MoneyStorage = game:GetService('ServerStorage').MoneyStorage
local Money = MoneyStorage:FindFirstChild(OwnerName)
Money.Value = Money.Value + hit.Cash.Value

This is, unfortunately, all I can do unless you provide further information. In the future, please try to clearly provide all relevant information in your question. Thanks!

1 comment

0

Thanks for the answer, worked for me!

This discussion is preserved as it was. New answers, comments, and votes are closed.