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 3 years ago

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

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

3 answers

Log in to vote
1
Answered by 3 years ago
Edited 3 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

local player = game.Players.LocalPlayer

while true do
    for _,object in pairs(player.leaderstats:GetChildren()) do
        wait()
    if object.Value == 1 then
        workspace.toto.TowerPortal.towername.BrickColor = BrickColor.new("Sea green")
        end 
    end
end

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

game.Players.PlayerAdded:connect(function(player)
    local leaderstats = Instance.new("Folder")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = player

    local Green = Instance.new("IntValue") 
    Green.Name = "Green" 
    Green.Parent = leaderstats

end)


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

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

Howdy!

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

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

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 3 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