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

Why won't my boolean value change?

Asked by 5 years ago

I made a script to change a boolean value from false to true when the robux value was greater than or equal to 100. But im getting the error: 15:43:41.837 - Players.CarmiteStars.PlayerGui.Menu.MenuFrame.AdvancementOpener.AdvancementFrame.Adv2.Adv2Script:1: attempt to index field 'LocalPlayer' (a nil value)

while true do

wait()

local player = game.Players.LocalPlayer

local robux = player:WaitForChild("stats"):FindFirstChild("robux")

local adv1 = player:WaitForChild("adv"):FindFirstChild("adv1")

if adv1 and robux then

if robux.Value >= 100 then

adv1.Value = true

end

end

end

If you could explain that would be great.

0
Local Script? AltNature 169 — 5y
0
Have you tried local player = game.Players:WaitForChild("LocalPlayer") AltNature 169 — 5y
0
@AltNature, Unless there is a player named "LocalPlayer", that wouldn't work. LocalPlayer should always exist because the PlayerObject itself is needed to run Local Scripts. The reason this doesn't work is probably because you used a server script rather than a local script. PhantomVisual 992 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago

Just had to change the script to a local script. Thanks commenters!

Ad
Log in to vote
0
Answered by 5 years ago

Its cause it a local script or if its a regular script then find the player some other way because. game.Players.LocalPlayer only works for local scripts. Also if u change a value for a localscript only scripts local to that player can see it

Answer this question