Scripting
The following objects are all used for creating new functions and systems in your game. Each script type has a different purpose which you can learn more about in our tutorials.
The NetworkEvent is used to send data between the server and client and vice versa. This is used to sync the information and data in your game and make sure everything is up to date.
When creating a NetworkEvent you must also create a NetMessage to send relevant information with your event.
The ScriptInstance is the base class of all scripts, it cannot be created or edited.
Example
For example you can create a server script for a weapon which uses a module to get the relevant information:
ToolModule.lua
local Settings = {
Damage = 20,
Cooldown = 0.8,
WeaponName = "Steel Sword"
}
return Settings
ToolScript.lua
local Tool = script.Parent
local Config = require(script.WeaponSettings)
local lastAttack = 0
Tool.Activated:Connect(function()
-- Check if we are still on cooldown
local currentTime = os.clock()
if currentTime - lastAttack < Config.Cooldown then
return
end
lastAttack = currentTime
print("Attacking with " .. Config.WeaponName .. " for " .. Config.Damage .. " damage!")
-- Logic for damaging players would go here
end)