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

local script cant detect value.Changed?

Heres my code [In a localscript]

local player = game.Players.LocalPlayer
local Cookies = player.leaderstats.Cookies

Cookies.Value.Changed:Connect(function()
	script.parent.Text = "Cookies value has changed"
end)

The error i get

 Players.Krosloe.PlayerGui.Shield.TextLabel.LocalScript:4: attempt to index field 'Value' (a number value)

2 answers

✓ Accepted answer

First, you could just remove the .Value to achieve what you want. However, here's a more efficient way:

local player = game.Players.LocalPlayer
local cookies = player.leaderstats.Cookies

Cookies:GetPropertyChangedSignal('Value'):Connect(function()
	script.Parent.Text = 'Cookies value has changed'
end)

Hope I helped!

3 comments

0

wth this is so useless

0

Thank you so much

0

Dear RobloxGameingStudios, in his/her opinion and apparently most people's, they like my answer better. There is nothing to be salty about

Easy Fix, You don't need to use Value.Changed for that...

local player = game.Players.LocalPlayer
local Cookies = player.leaderstats.Cookies

if Cookies.Value >= 1 then
    script.parent.Text = "Cookies value has changed"
end)

Pretty simple actually, i changed it to scan if the cookies value goes above 1, and complete the action below it.

I suggest using a while true do to always scan.

2 comments

0

-1 for suggesting loops over events.

0

WTH, why the heck would i waste time making the script above me

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