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

Confused why roblox output is saying "expected (to close 'function' at line 15) near '<eof>'"?

Code :

   --- MADE BY C7SN --- 

--- VAIRBLES ---
local Part = script.Parent -- this is the Part we will move
local newPos = Part.Position + Vector3.new(82.55, 19.96, 59.85) -- the position the Part will go to
local Time = 10 -- the time that the script will take to move the part
local Increment = 0.5 -- the Part will move 0.5 studs each time it moves
local Debounce = false
local Diff = newPos - Part.Position -- the difference between the two positions
local Mag = Diff.magnitude -- the distance between the two parts
local Direction = CFrame.new(Part.Position, newPos).lookVector

--- FUNCTION ---
workspace.Part.Touched:connect(function(otherPart)
	function MovePart() -- function to move the Part
 	if Debounce then return end -- end the function if debounce is true
	Debounce = true -- make Debounce true so the function can't run
	for n = 0, Mag, Increment do
		Part.CFrame = Part.CFrame + (Direction * Increment)
		wait( (Time/Mag) * Increment )
	
	end
	Debounce = false -- set Debounce to false so the function can run again
	end
	
workspace.Button.ClickDetector.MouseClick:connect(otherPart)

2 answers

That other function inside the event isn't needed. And you forgot a ')'

   --- MADE BY C7SN --- 

--- VAIRBLES ---
local Part = script.Parent -- this is the Part we will move
local newPos = Part.Position + Vector3.new(82.55, 19.96, 59.85) -- the position the Part will go to
local Time = 10 -- the time that the script will take to move the part
local Increment = 0.5 -- the Part will move 0.5 studs each time it moves
local Debounce = false
local Diff = newPos - Part.Position -- the difference between the two positions
local Mag = Diff.magnitude -- the distance between the two parts
local Direction = CFrame.new(Part.Position, newPos).lookVector

--- FUNCTION ---
workspace.Part.Touched:connect(function(otherPart)
    if Debounce then return end -- end the function if debounce is true

    Debounce = true -- make Debounce true so the function can't run

    for n = 0, Mag, Increment do
        Part.CFrame = Part.CFrame + (Direction * Increment)
        wait( (Time/Mag) * Increment )
    end

    Debounce = false -- set Debounce to false so the function can run again
end)

workspace.Button.ClickDetector.MouseClick:connect(otherPart)

1 comment

0

On the very last line (line 27) It's suppose to to connect to "workspace.Part.Touched:connect(function(otherPart)" and not "workspace.Button.ClickDetector.MouseClick:connect(otherPart)" how do I fix it so the last line lines up with the function?

You simply needed a parenthesis and another end (you might have found this if you indented properly), and simply means "end of file", or just near the end of the script. So, all you need another end with a closing parenthesis.

Hope this helps!

3 comments

0

thanks for the help, but now I've encountered a new problem on line 27, not matching with the function, help would be appreciated!

0

yeah uhh im just gonna hack into your studio and find the new code and the problem

0

...

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