Commentaire d’une ligne :
–print(« instruction en commentaire »)
Commentaire de plusieurs instructions :
–[[
print(« instruction en commentaire »)
print(« instruction en commentaire »)
–]]
Recherche d’une ressource dans un script :
local btOpenMenu = script.Parent.OpenButton
Comment détecter un click de la souris sur un bouton :
btOpenMenu.MouseButton1Click:Connect(function()
end)
Comment déplacer un objet Roblox :
myPart.Position += Vector3.new(10,0,0)
Déplacer un objet x fois :
for i = 1, 50 do
maPart.Position += Vector3.new(5,0,0)
wait(1)
end
Déplacer un objet Roblox tout le temps :
while true do
maPart.Position += Vector3.new(0.05,0,0)
wait(0.01)
end
Déplacer un objet jusqu’à une position :
while maPart.Position.X<60 do
maPart.Position += Vector3.new(5,0,0)
wait(0.01)
end
Synchroniser le déplacement avec le moteur de Roblox :
game:GetService(« RunService »).Heartbeat:Connect(function()
maPart.Position += Vector3.new(0.05,0,0)
end)
Comment détecter une collision du joueur avec un objet Roblox :
maPart.Touched:Connect(function(otherPart)
local character = otherPart.Parent
local player = game:GetService(« Players »):GetPlayerFromCharacter(character)
if player then
local humanoid = character:FindFirstChildWhichIsA(« Humanoid »)
if humanoid then
print(« le joueur touche le part »)
end
endend)
Comment détecter une fin de collision avec le joueur :
maPart.TouchEnded:Connect(function(otherPart)
local character = otherPart.Parent
local player = game:GetService(« Players »):GetPlayerFromCharacter(character)
if player then
local humanoid = character:FindFirstChildWhichIsA(« Humanoid »)
if humanoid then
print(« le joueur ne touche plus le part »)
end
endend)
Santé du joueur à 100 au départ du jeu :
print(humanoid.Health)
Réduire la santé du joueur :
humanoid.Health = humanoid.Health – 5
ou
humanoid:TakeDamage((5))
Le joueur meurt quand sa santé est à zéro :
humanoid.Health = 0
Comment coder un ClickDetector sur le part :

local clickDetector = script.Parent.ClickDetector
clickDetector.MouseClick:Connect(function()
print(« touché »)
end)
Comment coder un Prompt :


maPart.ProximityPrompt.Triggered:Connect(function(otherPart)
print(‘activé’)
end)