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

Is there a way to make a "variable function" run inside of a function?[SOLVED]

What I mean by "variable function" is to have a premade function run. Ex:

function speed(p)
game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 0
end

script.Parent.MouseButton1Click:Connect(function()
--- Here would run "speed"
end

Sorta like how RemoteEvents Work

3 comments

0

???

0

when you click the button it will make ur walkspeed = 0, from the function "speed"

0

Incorrect use of terminology can be very confusing for others. It's just called a 'function'. If I were to re-word your question, it would become "How do I call a function?". Your question could have been answered easily if you were willing to do a bit of research. Have a look at this wiki post for more on functions: http://wiki.roblox.com/index.php?title=Scripting_Book/Chapter_2

1 answer

✓ Accepted answer

??????

function speed(p)
game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 0
end

script.Parent.MouseButton1Click:Connect(function()
	speed() -- ?????

	--game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 0
	-- why dont you just set the speed in here?
end

?????

4 comments

0

This is what is was looking for but I had already solved it on wiki. Ill still accept tho i guess

0

It was an example btw, but can i put the function "speed" in a module script and still play it from the module?

0

You can put it in a module script, then call it from a different script.

0

you can just not use an anonymous function and use the speed function as the first parameter of the connect function

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