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

How to change part.Color once a value changes?

Asked by 3 years ago
game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(char)
        workspace:WaitForChild(player.Name)
        local clone = game.ReplicatedStorage.Cursor:Clone()
        clone.Parent = workspace[player.Name].Head
        clone.Position = workspace[player.Name].Head.Position
        local weld = Instance.new("Weld")
        weld.Parent = clone
        weld.Part0 = clone
        weld.Part1 = workspace[player.Name].Head
        weld.C0 = CFrame.new(0,-3,0)
        while true do
            wait(math.min)
            if reputation == 100 then
                clone.Color = Color3.fromRGB(0,255,0)
            elseif reputation < 75 and reputation > 25 then
                clone.Color = Color3.fromRGB(255,255,0)
            elseif reputation < 25 then
                clone.Color = Color3.fromRGB(255,0,0)
            end
        end
    end)
end)

Basically the script clone a part from Replicated Storage and puts it inside the Head of the player and welds it, after that, it checks if the reputaion of the player is lower then certain numbers, but it won't change the color if the value changes later on in the game.

3 answers

Log in to vote
1
Answered by
imKirda 4491 Moderation Voter Community Moderator
3 years ago

If value is an instance, you can use :GetPropertyChangedSignal(), it will call a function every time your desired property gets changed, here is example of using it:

local value = Instance.new("NumberValue")

value:GetPropertyChangedSignal("Value"):Connect(function()
    print("Value has changed!")
end)

Inside of the brackets, you must put property of the value instance and every time it changes, it should print Value has changed.

Ad
Log in to vote
0
Answered by 3 years ago

You can use GetPropertyChangedSignal

--parent a numbervalue called reputation in the local player

game.Players.PlayerAdded:Connect(function(player)
    local reputation = Instance.new("NumberValue",player)
end)

reputation:GetPropertyChangedSignal("Value"):Connect(function()
    wait()
                if reputation == 100 then
                    clone.Color = Color3.fromRGB(0,255,0)            
            elseif reputation < 75 and reputation > 25 then
                    clone.Color = Color3.fromRGB(255,255,0)
                elseif reputation < 25 then
                    clone.Color = Color3.fromRGB(255,0,0)
                end

end)

When the VALUE gets changed, everything inside the GPCS function will fire.

Log in to vote
0
Answered by 3 years ago
local value = Instance.new("IntValue")

value:GetPropertyChangedSignal("Value"):Connect(function()
print("The value has been changed")
end)

This will detect when the value is changed, so you can do:

local value = Instance.new("IntValue")
local brick = Instance.new("Part")


value:GetPropertyChangedSignal("Value"):Connect(function()
brick.Color = BrickColor3.new(math.Random)
end)

This should work, please mark as solved if this helped!

Answer this question