I have a script that is supposed to play effects when a player misses a note, but when wrapped in a coroutine, it gives multiple errors and warnings and I don’t know how to fix them. Can anyone help?
Script
if input.UserInputState ~= Enum.UserInputState.Begin then return end
coroutine.wrap(function() --line 431
userinput:FireServer(
"missed", direction .. "|" .. "0")
--\\ Note Miss Sound
ui.Sounds:GetChildren()[math.random(1,#ui.Sounds:GetChildren())]:Play()
--\\ Face
local FaceAssetID = player.Character.Head.face.Texture
local MissFaceAssetID = 7259402800
player.Character.Head.face.Texture = string.format("rbxthumb://type=Asset&id=%s&w=420&h=420", MissFaceAssetID)
--\\ Overlay
local arrow = side.Arrows[direction]
arrow.Overlay.ImageTransparency = 0
arrow.Overlay.Visible = true
arrow.ImageTransparency = 1
arrow.Size = UDim2.new(0.75,0,0.75,0)
arrow.Rotation = -15
game.TweenService:Create(arrow,TweenInfo.new(0.5,Enum.EasingStyle.Quint,Enum.EasingDirection.Out,0,false,0),
{Size=UDim2.new(1,0,1,0);Rotation=0}):Play()
game.TweenService:Create(arrow.Overlay,TweenInfo.new(0.25,Enum.EasingStyle.Quint,Enum.EasingDirection.Out,0,false,0.25),
{ImageTransparency=1}):Play()
arrow.ImageTransparency = 0
task.wait(0.50)
player.Character.Head.face.Texture = FaceAssetID
end -- tried putting ')', tried deleting it, didn't work either.
end)() -- errors syntax error: Expected 'end' (to close 'else' at line 429), got 'elseif'; did you forget to close 'function' at line 431?
It’s easier to help you if you indent your code properly before posting. If you don’t know how to indent code correctly, use this web tool to do it for you - however, given your code has a syntax error, that won’t help much.
The issue is that you added an extra end. I’ve boxed in the one to delete here:
I think I see how you may have gotten confused and decided to add another end. The line of code at the top is an if statement, and you’re probably used to seeing an end somewhere below that to close it off. In this case though, the if statement doesn’t contain lines of code inside, as it’s just 1 line. It’s got end at the end of its own line.