Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

3 comments

0

tools have an unequipped event and an equipped event 

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?

0

This is a server script in a part.

1 answer

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

3 comments

0

This is not a tool. The script is just a normal part.

0

"I have a block that changes color and text when it the tool is in use"

0

if it's not a tool, it should be

This discussion is preserved as it was. New answers, comments, and votes are closed.