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

How can I change the color of block when the tool is not in use?

Asked by 5 years ago

I have a block that changes color and text when it the tool is in use. It doesn't work, even though the tool has its bool value changed to true. Anyone know how to fix this?

InUse = game.ServerStorage.Key1.InUse.Value
while true do
    if InUse == true then
        script.Parent.BrickColor = BrickColor.new("Really red")
        script.Parent.SurfaceGui.TextLabel.Text = "Key1: In Use"
        wait(1)
    elseif InUse == false then
            script.Parent.BrickColor = BrickColor.new("Bright green")
            script.Parent.SurfaceGui.TextLabel.Text = "Key1: Not In Use"
            wait(1)
    end
end
0
tools have an unequipped event and an equipped event  theking48989987 2147 — 5y
0
Depends on the script, Local Scripts can't collect data from Server Storage? Is this your issue? Try changing it to a Server Script? CrazyCorrs 98 — 5y
0
This is a server script in a part. CaptainD_veloper 290 — 5y

1 answer

Log in to vote
0
Answered by
Ziffixture 6913 Moderation Voter Community Moderator
5 years ago

Mostly issues occur from efficiency problems, in this case, this is probably what's causing your problem. @theking is right, tools have an equipped and unequipped event. It's best to use these to your advantage. For example...

local tool = --//Index your tool
local handle = --// index handle
local gui = --//Index GUI
local colors = {"Really red", "Bright green"} --//Optional

handle.BrickColor = BrickColor.new(colors[1]) --//Assuming 'handle' is the object being colored

tool.Equipped:Connect(function()
    handle.BrickColor = BrickColor.new(colors[2])
    gui:WaitForChild("TextLabel").Text = "Key1: In Use" --// Efficiency tip: Sometimes the script can run faster than the asset can load, so we yield it until it exists, this should be used to index most things.
end)

tool.Unequipped:Connect(function()
    handle.BrickColor = BrickColor.new(colors[1])
    gui:WaitForChild("TextLabel").Text = "Key1: Not In Use"
end)

Hope this fixes your problem

0
This is not a tool. The script is just a normal part. CaptainD_veloper 290 — 5y
0
"I have a block that changes color and text when it the *tool* is in use" Ziffixture 6913 — 5y
0
if it's not a tool, it should be Ziffixture 6913 — 5y
Ad

Answer this question