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

For some reason my if then isn't working with a value?

Asked by 4 years ago

Hello! I was wondering why this script wasn't working. It is in StarterGui in a local script

1while true do
2    if game.players.LocalPlayer.stats.Green.value = 1 then
3        workspace.toto.TowerPortal.towername.BrickColor = BrickColor.new ("Sea green")
4    end
5end

3 answers

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

It's not working because you are setting a value with one equals sign. Using 2 equals signs waits for a value, so to fix you would do

UPDATED:

This is in a local script inside of the starter gui

01local player = game.Players.LocalPlayer
02 
03while true do
04    for _,object in pairs(player.leaderstats:GetChildren()) do
05        wait()
06    if object.Value == 1 then
07        workspace.toto.TowerPortal.towername.BrickColor = BrickColor.new("Sea green")
08        end
09    end
10end

leaderstats script (If you already have one don't write this)

01game.Players.PlayerAdded:connect(function(player)
02    local leaderstats = Instance.new("Folder")
03    leaderstats.Name = "leaderstats"
04    leaderstats.Parent = player
05 
06    local Green = Instance.new("IntValue")
07    Green.Name = "Green"
08    Green.Parent = leaderstats
09 
10end)

This is probably really inefficient because im using some old methods but it works anyway :/

0
Thanks! I'll try that! User#39520 0 — 4y
0
I tried and it says Players.Stoutscientist.PlayerGui.LocalScript:1: Incomplete statement: expected assignment or a function call User#39520 0 — 4y
0
Also I made sure stats is in the local player so it isn't that User#39520 0 — 4y
0
Try adding a wait(). Darth_Revan404 30 — 4y
View all comments (4 more)
0
ok i'm trying to see what I did wrong TheStarRblx 27 — 4y
0
I re did mine but its probably bad and outdated but it still works! TheStarRblx 27 — 4y
0
THANK YOU SO MUCH IT WORKED User#39520 0 — 4y
0
np TheStarRblx 27 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

Howdy!

When writing statements, you use two equal signs. In other times, use just one. Try what I have below.

1while true do
2    if game.players.LocalPlayer.stats.Green.value == 1 then
3        workspace.toto.TowerPortal.towername.BrickColor = BrickColor.new ("Sea green")
4    end
5end

If this helped you out, consider accepting this answer for those sweet, sweet reputation points. If not, comment below and I (or someone else) will help you out.

Be sure to check out the Roblox API Documentation as well for additional reference.

Log in to vote
0
Answered by 4 years ago

On top of the past answers, .Value and .Players need to be capitalized in "game.players.LocalPlayer.stats.Green.value"

Answer this question