That’s not an error. Go to the view tab, and press output, then run your game and show any red text that’s in there.
What is the point of all the other else statements?
You’ve put too many else
statements, there can only be only 1 else
at the very end. If you want to have a condition to check like at the very start, then use else if
.
Can you explain what you’re trying to do
This is based on my previous post, How to make it activated twice and not at the same time - #2 by Emskipo.
But I want to add more Scrolls and not only 2.
You need to tell us what this code is supposed to do to the tool, as well as tell us what the tool is, otherwise we don’t really know what you’re trying to do altogether.
It will make one scroll become invisible if you click it once (activate it) and not all at the same time and then if you click it again, one scroll will become invisible.
Is there a certain order that the scrolls become invisible? Does one new scroll become invisible each time you click?
Try this, activated only returns true or false, and you can only have one else statement so you have to create a variable (activateCount) that increases each time it’s been activated and use elseif to check it.
See this for more info Control Structures | Roblox Creator Documentation
local tool = script.Parent
local activateCount = 0
tool.Activated:Connect(function()
activateCount += 1
if activateCount == 1 then
tool.Handle.Scroll1A.Transparency = 1
tool.Handle.Scroll1B.Transparency = 1
elseif activateCount == 2 then
tool.Handle.Scroll2A.Transparency = 1
tool.Handle.Scroll2B.Transparency = 1
elseif activateCount == 3 then
tool.Handle.Scroll3A.Transparency = 1
tool.Handle.Scroll3B.Transparency = 1
elseif activateCount == 4 then
tool.Handle.Scroll4A.Transparency = 1
tool.Handle.Scroll4B.Transparency = 1
elseif activateCount == 5 then
tool.Handle.Scroll5A.Transparency = 1
tool.Handle.Scroll5B.Transparency = 1
elseif activateCount == 6 then
tool.Handle.Scroll6A.Transparency = 1
tool.Handle.Scroll6B.Transparency = 1
end
end)
Oh, we just posted the same thing. I will delete my post
Oh I’m sorry I was editing and I didn’t see your post
It seems like it starts from Scroll 6.
Are the scrolls placed in the correct order?
Nevermind, they work great. Thanks to you and oopacity for solving it.
local tool = script.Parent
local activateCount = 0
local Activations = {
[1] = {tool.Handle.Scroll1A, tool.Handle.Scroll1B},
[2] = {tool.Handle.Scroll2A, tool.Handle.Scroll2B},
[3] = {tool.Handle.Scroll3A, tool.Handle.Scroll3B},
[4] = {tool.Handle.Scroll4A, tool.Handle.Scroll4B},
[5] = {tool.Handle.Scroll5A, tool.Handle.Scroll5B},
[6] = {tool.Handle.Scroll6A, tool.Handle.Scroll6B},
}
tool.Activated:Connect(function()
if activateCount > #Activations then
return;
end
activateCount += 1
if Activations[activateCount] then
Activations[Activations][1].Transparency = 1
Activations[Activations][2].Transparency = 1
end
end)
This should work was well, I think it’s better than use 5 elseif’s.
local tool = script.Parent
local handle = tool.Handle
local activateCount = 0
tool.Activated:Connect(function()
activateCount += 1
for _, Child in ipairs(handle:GetChildren()) do
if Child.Name:match("^Scroll"..activateCount) then
Child.Transparency = 1
end
end
end)