Roblox Helpful Code

Create a Store

Instructions:

Click here for the source of this tutorial

Create Fire

Instance.new('Fire', Game.Workspace.Terrain).Size = 100

Create Explosion

Instance.new("Explosion", Game.Workspace.Terrain)

Important Note!

The 'Player' and its script only shows during the game and not when your development the game.

Adding Messages

game.Players.PlayerAdded:connect(function(player)
local msg = Instance.new('Message', Workspace)
msg.Text = player.Name .. " has entered the game."
wait(5)
msg:Destroy()
end)

Adding basic Touch Events

local part = Instance.new('Part', Workspace)
part.Touched:connect(function()
print("Part was touched.")
end)

Adding a Clickable Part

local part, clickd, msg = Workspace.Part, Instance.new('ClickDetector'), Instance.new('Message')
clickd.Parent = part
msg.Text = "Clicked!"

clickd.MouseClick:connect(function()
msg.Parent = Workspace
wait(2)
msg.Parent = nil
end)

Touch and Explode

Workspace.Part.Touched:connect(function(hit)
if hit.Parent and game.Players:GetPlayerFromCharacter(hit.Parent) then
local exp = Instance.new('Explosion', Workspace)
exp.Position = hit.Position
end
end)

Leaderboard (Cookbook chapter 4)

game.Players.PlayerAdded:connect(function(player)
local leader, score = Instance.new('IntValue', player),
Instance.new('IntValue')
leader.Name = 'leaderstats'
score.Name = 'Score'
score.Parent = leader
end)

Changing to Daytime/Nighttime

game.Lighting:SetMinutesAfterMidnight(5 * 60)

Adding Points for Touching a Zombie's Left Arm

function addPoints(player)
local findScore = game.Players:FindFirstChild(player.Parent.Name)
findScore.leaderstats.Score.Value = findScore.leaderstats.Score.Value + 10
wait(5)
end

Game.Workspace["Drooling Zombie"]["Left Arm"].Touched:connect(addPoints)

Player has Died Message

game:GetService('Players').PlayerAdded:connect(function(player)
player.CharacterAdded:connect(function(character)
character:WaitForChild("Humanoid").Died:connect(function()
local msg = Instance.new('Message', Workspace)
msg.Text = player.Name .. " has died in vain."
wait(5)
msg:Destroy()
end)
end)
end)

Roblox Cookbook

Link