Difference between types of scripts

What is the difference between scripts, local scripts, and module scripts? What are the different applications for each of them?

I put this code:

local clickDetector = script.Parent

function onMouseClick()
print(“You clicked me!”)
end

clickDetector.MouseClick:connect(onMouseClick)

into a local script that was inside of a ClickDetector and it didn’t work. However, when I used a script it did work. Why is this?

4 Likes

LocalScripts are for client-side use, scripts are server-sided. LocalScripts will only run in certain instances e.g. a player’s backpack, character, gui, playerscript folder etc. In contrast, scripts can run anywhere and have access to server-side objects/props/services.

Highly recommend you check out: Documentation - Roblox Creator Hub for documentation

6 Likes

These developer hub articles may help:

Scripts: Script | Documentation - Roblox Creator Hub
LocalScripts: LocalScript | Documentation - Roblox Creator Hub
ModuleScripts: ModuleScript | Documentation - Roblox Creator Hub

4 Likes