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

Can anyone please help me with this end error including elses?

Ok, essentially I have a LocalScript inside of a Tool. Everything about my tool works, but I have this pestering error that has been occuring. The error that shows up is as follows, "22:53:00.838 - Players.PLAYERNAMEREDACTED.Backpack.a.LocalScript:29: 'end' expected (to close 'function' at line 6) near 'else'".

Oh, and to explain the script. I have a script where when you equip a tool and press a certain key, there is a blur and music starts playing. When the blur size gets to a certain value, there is a for loop which gives the effect of text appearing. I only need to work on syntax errors. Also, if any of my vocabulary is wrong, please bear with it as I'm coming back to scripting in Roblox after a while, so I could be a little rough on it.

This is the code I have, as is listed below. I really need help with fixing up the ends, and I believe every if, function, and else has an end statement. All help is appreciated!

local music = script.Parent:WaitForChild("Piano")
visibleValue = workspace.HeyKids.Value
local blur = game.Lighting:WaitForChild("BlurEffect")
local player = game.Players.LocalPlayer
local tool = script.Parent
tool.Equipped:Connect(function(mouse)
	
		mouse.KeyDown:connect(function(key)
			if key:byte() == 96 then
				music.Playing = true
				music.Looped = true
				for m = 0,24.1,.1 do
					wait(.1)
					blur.Size = m
					if blur.Size == 24 then
						visibleValue = true
					end
				end
				if visibleValue == true then
					for i = 1,0,-.05 do
						player.PlayerGui.ScreenGui.Frame.TextLabel.TextTransparency = i
						wait(.01)
					end
				else
					player.PlayerGui.ScreenGui.Frame.TextLabel.TextTranparency = 1
				end
			end
		end)
				else if key:byte() == 127 then
					music.Playing = true
					music.Looped = true
					for n = 0,12.05,.05 do
						wait(.05)
						blur.Size = n
						if blur.Size == 12 then
							coolValue = true
						end
						if coolValue == true then
							player.PlayerGui.ScreenGui.Frame.TextLabel.Text = ("i have the high ground")
							for b = 1,0,-.05 do
								player.PlayerGui.ScreenGui.Frame.TextLabel.TextTransparency = b
								wait (.01)
							end
						else 
							player.PlayerGui.ScreenGui.Frame.TextLabel.TextTransparency = 1
						end
					end
				end
				end
	end)	
end)

tool.Unequipped:Connect(function()
	player.PlayerGui.ScreenGui.Enabled = false
	music.Playing = false
	blur.Size = 0
end)

If anyone can help, please list what is needed so I can get to work.

3 comments

0

You added elseif after closing your function? That won't work.

0

You added elseif after closing your function? That won't work.

0

dont ue keydown, it is deprecated, use InputBegan instead

1 answer

✓ Accepted answer

I haven't tested this since I don't know how should I replicate the hierarchy (or what you see in your Explorer window) to make this work.

Oh well, here you go!

local music = script.Parent:WaitForChild("Piano")
visibleValue = workspace.HeyKids.Value
local blur = game.Lighting:WaitForChild("BlurEffect")
local player = game.Players.LocalPlayer
local tool = script.Parent
tool.Equipped:Connect(function(mouse)
	mouse.KeyDown:connect(function(key)
		if key:byte() == 96 then
			music.Playing = true
			music.Looped = true
			for m = 0,24.1,.1 do
				wait(.1)
				blur.Size = m
				if blur.Size == 24 then
					visibleValue = true
				end
			end
			if visibleValue == true then
				for i = 1,0,-.05 do
					player.PlayerGui.ScreenGui.Frame.TextLabel.TextTransparency = i
					wait(.01)
				end
			else
				player.PlayerGui.ScreenGui.Frame.TextLabel.TextTranparency = 1
			end
		elseif key:byte() == 127 then
			music.Playing = true
			music.Looped = true
			for n = 0,12.05,.05 do
				local coolValue -- Script Analysis told me to do so...
				wait(.05)
				blur.Size = n
				if blur.Size == 12 then
					coolValue = true
				end
				if coolValue == true then
					player.PlayerGui.ScreenGui.Frame.TextLabel.Text = ("i have the high ground")
					for b = 1,0,-.05 do
						player.PlayerGui.ScreenGui.Frame.TextLabel.TextTransparency = b
						wait (.01)
					end
				else 
					player.PlayerGui.ScreenGui.Frame.TextLabel.TextTransparency = 1
				end
			end
		end
	end)
end)

tool.Unequipped:Connect(function()
	player.PlayerGui.ScreenGui.Enabled = false
	music.Playing = false
	blur.Size = 0
end)

I'd also suggest to not remove end's when you create a new loop, function, other whatnots and also rather than spaces, use the Tab key instead because it would be easier to read.

And you're welcome.

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