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

Problems with number values?

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

✓ Accepted answer

.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)

11 comments

0

????

0

so i remove the value?

0

i changed line 14 (or 13 in your original script) because it was wrong

0

yes, .Changed is called on the actual object, not the object's value

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.

1

notice how the passed parameter is the value name that changed: https://developer.roblox.com/api-reference/event/Instance/Changed

0

i added an example

1

good stuff gioni

0

thx dad. accept the answer if it helped tim, bc i saw you havent been accepting anyone's answers.

1

Events are not called

0

give me ur number and ill call u

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