Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Problems with number values?

Asked by 6 years ago
DS = game:GetService("DataStoreService")
MaxKi = DS:GetDataStore("kiMaxSave")
game.Players.PlayerAdded:Connect(function(plr)
    print(plr.Name.."has joined the game")
    local stats = Instance.new("Folder", plr)
    stats.Name = "Stats"
    KiMax = Instance.new("NumberValue", stats)
    KiMax.Name = "KiMax"
    KiMax.Value = MaxKi:GetAsync(plr.UserId) or 0
    KiValue = Instance.new("NumberValue", stats)
    KiValue.Name = "KiValue"
    KiValue.Value = KiMax.Value 
    KiMax.Value.Changed:Connect(function()
        MaxKi:SetAsync(plr.UserId, KiMax) 
    end)
end)

I've made this and it says

  18:14:38.674 - ServerScriptService.Script:13: attempt to index field 'Value' (a number value)

as an error.

1 answer

Log in to vote
3
Answered by 6 years ago
Edited 6 years ago

.Changed is an event of Instance, but you used it on the actual value of the instance, which is a number.

DS = game:GetService("DataStoreService")
MaxKi = DS:GetDataStore("kiMaxSave")
game.Players.PlayerAdded:Connect(function(plr)
    print(plr.Name.."has joined the game")
    local stats = Instance.new("Folder") --second argument of .new() deprecated
    stats.Name = "Stats"
    stats.Parent = plr
    KiMax = Instance.new("NumberValue", stats)
    KiMax.Name = "KiMax"
    KiMax.Value = MaxKi:GetAsync(plr.UserId) or 0
    KiValue = Instance.new("NumberValue", stats)
    KiValue.Name = "KiValue"
    KiValue.Value = KiMax.Value 
    KiMax.Changed:Connect(function()
        MaxKi:SetAsync(plr.UserId, KiMax) 
    end)
end)

Here's another example of using the event:

game:GetService("Players").PlayerAdded:Connect(function(plr)
   local IntValue = Instance.new("IntValue")
   IntValue.Parent = plr
   IntValue.Changed:Connect(function(property)
     print(property)
   end)
   wait(3)
   IntValue.Value = 5 --will print the name of the property changed - "Value"
end)
0
???? HappyTimIsHim 652 — 6y
0
so i remove the value? HappyTimIsHim 652 — 6y
0
i changed line 14 (or 13 in your original script) because it was wrong Gey4Jesus69 2705 — 6y
0
yes, .Changed is called on the actual object, not the object's value Gey4Jesus69 2705 — 6y
View all comments (7 more)
0
As he stated, .Changed is looking for changes in the Value of an instance, so since it already looks to the value theres no need to reference it directly. DinozCreates 1070 — 6y
1
notice how the passed parameter is the value name that changed: https://developer.roblox.com/api-reference/event/Instance/Changed Gey4Jesus69 2705 — 6y
0
i added an example Gey4Jesus69 2705 — 6y
1
good stuff gioni DinozCreates 1070 — 6y
0
thx dad. accept the answer if it helped tim, bc i saw you havent been accepting anyone's answers. Gey4Jesus69 2705 — 6y
1
Events are not called User#24403 69 — 6y
0
give me ur number and ill call u Gey4Jesus69 2705 — 6y
Ad

Answer this question