I have a localscript and it is supposed to toggle visibility when a player reaches certain leaderstats. However, when one player reaches the stats, the whole server gets the visibility toggled. I'm a bit new to scripting so I'm not sure where I went wrong.
while true do for i,v in pairs(game.Players:GetChildren()) do if v.leaderstats.Level.Value >= 2 then script.Parent.Main.Archer.Visible = true script.Parent.Covers.ArcherCover.Visible = false script.Parent.Frame.Archer.Visible = true end if v.leaderstats.Level.Value >= 3 then script.Parent.Main.Skeleton.Visible = true script.Parent.Covers.SkeletonCover.Visible = false script.Parent.Frame.Skeleton.Visible = true end if v.leaderstats.Level.Value >= 4 then script.Parent.Main.LavaBaron.Visible = true script.Parent.Covers.LavaBaronCover.Visible = false script.Parent.Frame.LavaBaron.Visible = true end if v.leaderstats.Level.Value >= 5 then script.Parent.Main.Pikeman.Visible = true script.Parent.Covers.PikemanCover.Visible = false script.Parent.Frame.Pikeman.Visible = true end end wait(1) end
Use a LocalScript
instead of a script. This makes thing much easier for you. All you need to do is to create a LocalScript inside either in the StarterPack
or StarterPlayer>StarterPlayerScripts
, which ever one you prefer.
Also I changed your script:
for i,v in pairs(game.Players:GetChildren()) do
Instead of a for loop. You can do this instead.
local v = game.Players.LocalPlayer -- This makes things much easier! and Much more simple. while true do if v.leaderstats.Level.Value >= 2 then script.Parent.Main.Archer.Visible = true script.Parent.Covers.ArcherCover.Visible = false script.Parent.Frame.Archer.Visible = true end if v.leaderstats.Level.Value >= 3 then script.Parent.Main.Skeleton.Visible = true script.Parent.Covers.SkeletonCover.Visible = false script.Parent.Frame.Skeleton.Visible = true end if v.leaderstats.Level.Value >= 4 then script.Parent.Main.LavaBaron.Visible = true script.Parent.Covers.LavaBaronCover.Visible = false script.Parent.Frame.LavaBaron.Visible = true end if v.leaderstats.Level.Value >= 5 then script.Parent.Main.Pikeman.Visible = true script.Parent.Covers.PikemanCover.Visible = false script.Parent.Frame.Pikeman.Visible = true end end wait(1) end
Just copy and paste this code into the LocalScript you created. I hope this worked for you.