Local script doesn't work

The Script:

local holdingval = game.ReplicatedStorage.holdingval.Value
local holdingv = game.ReplicatedStorage.holdingval

function pick()
if holdingval == 10 then
ten.BackgroundColor3 = Color3.new(1, 1, 1)
end
if holdingval == 20 then
twenty.BackgroundColor3 = Color3.new(1, 1, 1)
end
if holdingval == 30 then
thirty.BackgroundColor3 = Color3.new(1, 1, 1)
end
if holdingval == 40 then
fourty.BackgroundColor3 = Color3.new(1, 1, 1)
end
if holdingval == 50 then
print(“tried5”)
fifty.BackgroundColor3 = Color3.new(1, 1, 1)
end
end

holdingv.Changed:Connect(function()
pick()
end)

holdingval is a NumberValue in Replicated Storage, the if statements don’t do anything, even when the statement is true, and the number is 10,20,30,40,50 etc… Does anyone know the solution?

1 Like

Are there any errors? because the value might not have loaded in on the client.

Also, Use ``` before and after your scripts to make them look better here on the devforum, like so:

script
3 Likes

the code that fixed should be:

local holdingv = game.ReplicatedStorage.holdingval

function pick()
    local holdingval = holdingv.Value

    if holdingval == 10 then
        ten.BackgroundColor3 = Color3.new(1, 1, 1)
    end
-- the rest just the same as above
    if holdingval == 20 then
        twenty.BackgroundColor3 = Color3.new(1, 1, 1)
    end

    if holdingval == 30 then
        thirty.BackgroundColor3 = Color3.new(1, 1, 1)
    end

    if holdingval == 40 then
        fourty.BackgroundColor3 = Color3.new(1, 1, 1)
    end

    if holdingval == 50 then
        print("Tried 5")
        fifty.BackgroundColor3 = Color3.new(1, 1, 1)
    end
end

holdingv.Changed:Connect(function()
    pick()
end)

i don’t know if it work

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.