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

local script cant detect value.Changed?

Asked by 4 years ago

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

Log in to vote
2
Answered by
U_srname 152
4 years ago

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!

0
wth this is so useless RobloxGameingStudios 145 — 4y
0
Thank you so much User#29320 0 — 4y
0
Dear RobloxGameingStudios, in his/her opinion and apparently most people's, they like my answer better. There is nothing to be salty about U_srname 152 — 4y
Ad
Log in to vote
-3
Answered by 4 years ago

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.

0
-1 for suggesting loops over events. User#24403 69 — 4y
0
WTH, why the heck would i waste time making the script above me RobloxGameingStudios 145 — 4y

Answer this question