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

Getting an error 'end expected'?

Hey there, new scripter here,

The script works fine but i get an error causing it to not work as intended,

Error = Players.Aozwel.PlayerGui.MainDialogs.Stage2.StatusBar.Frame.TextLabel.LocalScri:47: 'end' expected (to close 'if' at line 15) near ''

Code =

-- STAGE 2
local dialogGui = script.Parent
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local object = script.Parent
local host = workspace.Host
local guiObject = script.Parent
local myThread = coroutine.running()

function continueDialog()
    coroutine.resume(myThread)
end

host.Touched:Connect(continueDialog)
workspace.host.Touched:Connect(function(hit)
 if hit.Parent:findFirstChild("Humanoid") then
	guiObject.Visible = true
	
-- Require module

	
local TypeWriter = require(ReplicatedStorage:WaitForChild("TypeWriter"))
	coroutine.yield()
 	wait(1)
TypeWriter.typeWrite(script.Parent, "Head on over to the Potion Class!")
	wait(1)
	TypeWriter.typeWrite(script.Parent, "Hello there students my name is Professor Herbert")
	wait(1)
	TypeWriter.typeWrite(script.Parent, "Would you like to help me create my newest Potion?")
	wait(1)
	TypeWriter.typeWrite(script.Parent, "Great! I’ll need the following ingredients..")
	wait(1)
	TypeWriter.typeWrite(script.Parent, "They should all be hidden somewhere within the classes go look!")
	wait(1)
	
	
object.AnchorPoint = Vector2.new(0, 0)
object.Position = UDim2.new{0, 0},{0, 0}
 
 
object:TweenPosition(UDim2.new(0, 0, -10.04, 0), Enum.EasingDirection.In, Enum.EasingStyle.Sine,0.5)

wait(2)

script.parent.Visible = false
	if script.parent.visible == false then print("Worked!")
		
end

Thanks,

1 comment

0

After line 47 put an end). You didn't close the function body with the end keyword. The parenthesis is there to close of the :Connect() call.

1 answer

✓ Accepted answer

Hello, an "end" is expected to close the if at line 15. Your code shoud be:

-- STAGE 2
local dialogGui = script.Parent
--local ReplicatedStorage = game:GetService("ReplicatedStorage")
local object = script.Parent
local host = workspace.Host
local guiObject = script.Parent
local myThread = coroutine.running()

-- Local type writer
function localTypeWriter(textElement, goal)
    for i=1, string.len(goal), 1 do
        textElement.Text = string.sub(goal,1,i)
        wait(.2)
    end
end

function continueDialog()
    coroutine.resume(myThread)
end

host.Touched:Connect(continueDialog)
workspace.host.Touched:Connect(function(hit) -- Missing end for this function
    if hit.Parent:findFirstChild("Humanoid") then -- Missing end for this if
        guiObject.Visible = true

        -- Require module
        --local TypeWriter = require(ReplicatedStorage:WaitForChild("TypeWriter"))
        --coroutine.yield()
        -- Ajust the wait values to fit your time.
        wait(1)
        localTypeWriter(script.Parent, "Head on over to the Potion Class!")
        wait(1)
        localTypeWriter(script.Parent, "Hello there students my name is Professor Herbert")
        wait(1)
        localTypeWriter(script.Parent, "Would you like to help me create my newest Potion?")
        wait(1)
        localTypeWriter(script.Parent, "Great! I’ll need the following ingredients..")
        wait(1)
        localTypeWriter(script.Parent, "They should all be hidden somewhere within the classes go look!")
        wait(1)


        object.AnchorPoint = Vector2.new(0, 0)
        object.Position = UDim2.new{0, 0},{0, 0}


        object:TweenPosition(UDim2.new(0, 0, -10.04, 0), Enum.EasingDirection.In, Enum.EasingStyle.Sine,0.5)

        wait(2)

        script.parent.Visible = false
        if script.parent.Visible == false then 
            print("Worked!")
        end
    end -- Line added
end) -- Line added

Or maybe your are missing the end for the if at line 45.

Some identation should help you next time ;)

18 comments

1

That just gave me another 'End' error elsewhere? Players.Aozwel.PlayerGui.MainDialogs.Stage2.StatusBar.Frame.TextLabel.LocalScri:48: 'end' expected (to close 'function' at line 14) near ''

0

Got this now? Players.Aozwel.PlayerGui.MainDialogs.Stage2.StatusBar.Frame.TextLabel.LocalScri:49: ')' expected (to close '(' at line 14) near ''

1

Sorry, I didin't found the missing bracket, have you copied the full code?

0

I have seemed to have got it working for the most part, However the text isnt appearing at Line 24, Just the gui pops up

1

Have you copied the TypeWriter script from roblox developer wiki? Or you forgot it?

0

Yeah the TypeWriter is from the wiki

1

I didn't found a way to make the TypeWriter works... So I made a local TypeWriter (code edited)

0

Alright lemme try that, However i did manage to get it to work with my script by removing the Touched and Visible = true so im wondering if thats the issue i need to fix?

1

At line 51, "Visible" was starting lowercase, while it should be starting upercase

0

Yours seems to be doing the same thing as mine and not displaying the Text, However i noticed "localTypeWriter" has a blue line under it?, Not sure if thats a problem but i see no Errors in output,

1

I missed an "r" at the funtion name, that's why the blue lines under the code.

0

Still nothing, Not sure what is causing this but its very close to being able to work

1

I've created a test zone, and it works now. Just remove the "coroutine.yield()" and ajust the wait time.

0

It worked, Thanks so much for your time, However how would i change the settings like speed and sutff?, Also how would i go about making it a cooldown cause rn it can be spammed

1

Speed is just adjust the wait() values, "sutff"? I didin't understood that. For the cooldown just google "Roblox Debounce" and you will found an solution.

0

I meant like the speed of the Text generating cause its rather slow at the moment

2

Just go at the localTypeWriter function and decrease it wait value.

0

Thanks for all your help!, Really appreciate it, I looked into the debounce thing tho i'm unsure were i should place it in my Script as i get the End errors again

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