I'll help you create a "Steal Lucky Blocks" game for Roblox! Here's the complete code structure:
ServerScriptService Scripts
Main Game Handler (ServerScriptService)
-- GameHandler
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
-- Create RemoteEvents
local remotes = Instance.new("Folder")
remotes.Name = "Remotes"
remotes.Parent = ReplicatedStorage
local stealRemote = Instance.new("RemoteEvent")
stealRemote.Name = "StealLuckyBlock"
stealRemote.Parent = remotes
local openBlockRemote = Instance.new("RemoteEvent")
openBlockRemote.Name = "OpenLuckyBlock"
openBlockRemote.Parent = remotes
-- Player Data
local playerData = {}
-- Initialize player data
local function initializePlayer(player)
playerData[player.UserId] = {
luckyBlocks = 0,
cooldown = false
}
-- Create leaderstats
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local luckyBlocks = Instance.new("IntValue")
luckyBlocks.Name = "LuckyBlocks"
luckyBlocks.Value = 0
luckyBlocks.Parent = leaderstats
end
-- Handle stealing
stealRemote.OnServerEvent:Connect(function(thief, victim)
if not victim or not victim:IsA("Player") then return end
if thief == victim then return end
local thiefData = playerData[thief.UserId]
local victimData = playerData[victim.UserId]
if not thiefData or not victimData then return end
if thiefData.cooldown then return end
-- Check distance
local thiefChar = thief.Character
local victimChar = victim.Character
if not thiefChar or not victimChar then return end
local thiefRoot = thiefChar:FindFirstChild("HumanoidRootPart")
local victimRoot = victimChar:FindFirstChild("HumanoidRootPart")
if not thiefRoot or not victimRoot then return end
local distance = (thiefRoot.Position - victimRoot.Position).Magnitude
if distance > 20 then return end -- Too far away
-- Steal logic
if victimData.luckyBlocks > 0 then
local stealAmount = math.random(1, math.min(3, victimData.luckyBlocks))
victimData.luckyBlocks = victimData.luckyBlocks - stealAmount
thiefData.luckyBlocks = thiefData.luckyBlocks + stealAmount
-- Update leaderstats
thief.leaderstats.LuckyBlocks.Value = thiefData.luckyBlocks
victim.leaderstats.LuckyBlocks.Value = victimData.luckyBlocks
-- Cooldown
thiefData.cooldown = true
task.wait(3)
thiefData.cooldown = false
end
end)
-- Handle opening lucky blocks
openBlockRemote.OnServerEvent:Connect(function(player)
local data = playerData[player.UserId]
if not data or data.luckyBlocks <= 0 then return end
data.luckyBlocks = data.luckyBlocks - 1
player.leaderstats.LuckyBlocks.Value = data.luckyBlocks
-- Random rewards
local rewards = {
{name = "Speed Boost", chance = 30, effect = "speed"},
{name = "Jump Boost", chance = 25, effect = "jump"},
{name = "Extra Lucky Blocks", chance = 20, effect = "blocks"},
{name = "Invisibility", chance = 15, effect = "invisible"},
{name = "Giant Size", chance = 10, effect = "giant"}
}
local roll = math.random(1, 100)
local currentChance = 0
for _, reward in ipairs(rewards) do
currentChance = currentChance + reward.chance
if roll <= currentChance then
applyReward(player, reward)
break
end
end
end)
-- Apply rewards
function applyReward(player, reward)
local character = player.Character
if not character then return end
local humanoid = character:FindFirstChild("Humanoid")
if not humanoid then return end
if reward.effect == "speed" then
humanoid.WalkSpeed = 32
task.wait(15)
humanoid.WalkSpeed = 16
elseif reward.effect == "jump" then
humanoid.JumpPower = 100
task.wait(15)
humanoid.JumpPower = 50
elseif reward.effect == "blocks" then
local data = playerData[player.UserId]
local bonus = math.random(2, 5)
data.luckyBlocks = data.luckyBlocks + bonus
player.leaderstats.LuckyBlocks.Value = data.luckyBlocks
elseif reward.effect == "invisible" then
for _, part in ipairs(character:GetDescendants()) do
if part:IsA("BasePart") and part.Name ~= "HumanoidRootPart" then
part.Transparency = 0.9
end
end
task.wait(10)
for _, part in ipairs(character:GetDescendants()) do
if part:IsA("BasePart") and part.Name ~= "HumanoidRootPart" then
part.Transparency = 0
end
end
elseif reward.effect == "giant" then
character:ScaleTo(2)
task.wait(20)
character:ScaleTo(1)
end
end
-- Player joined
Players.PlayerAdded:Connect(initializePlayer)
-- Player leaving
Players.PlayerRemoving:Connect(function(player)
playerData[player.UserId] = nil
end)
-- Spawn lucky blocks periodically
while true do
task.wait(5)
for _, player in ipairs(Players:GetPlayers()) do
local data = playerData[player.UserId]
if data then
data.luckyBlocks = data.luckyBlocks + 1
if player.leaderstats then
player.leaderstats.LuckyBlocks.Value = data.luckyBlocks
end
end
end
end
Lucky Block Spawner (ServerScriptService)
-- LuckyBlockSpawner
local workspace = game:GetService("Workspace")
local RunService = game:GetService("RunService")
local blockFolder = Instance.new("Folder")
blockFolder.Name = "LuckyBlocks"
blockFolder.Parent = workspace
local function createLuckyBlock()
local block = Instance.new("Part")
block.Name = "LuckyBlock"
block.Size = Vector3.new(4, 4, 4)
block.Material = Enum.Material.Neon
block.BrickColor = BrickColor.new("Bright yellow")
block.TopSurface = Enum.SurfaceType.Smooth
block.BottomSurface = Enum.SurfaceType.Smooth
-- Random position
local x = math.random(-50, 50)
local z = math.random(-50, 50)
block.Position = Vector3.new(x, 10, z)
-- Add floating effect
local bodyPosition = Instance.new("BodyPosition")
bodyPosition.MaxForce = Vector3.new(0, math.huge, 0)
bodyPosition.Position = block.Position
bodyPosition.Parent = block
-- Add spinning
local bodyAngularVelocity = Instance.new("BodyAngularVelocity")
bodyAngularVelocity.AngularVelocity = Vector3.new(0, 2, 0)
bodyAngularVelocity.MaxTorque = Vector3.new(0, math.huge, 0)
bodyAngularVelocity.Parent = block
block.Parent = blockFolder
-- Float animation
local startY = block.Position.Y
local connection
connection = RunService.Heartbeat:Connect(function()
if block.Parent then
bodyPosition.Position = Vector3.new(
block.Position.X,
startY + math.sin(tick() * 2) * 2,
block.Position.Z
)
else
connection:Disconnect()
end
end)
-- Remove after time
task.wait(math.random(20, 40))
block:Destroy()
end
-- Spawn blocks continuously
while true do
task.wait(math.random(3, 8))
if #blockFolder:GetChildren() < 10 then
createLuckyBlock()
end
end
StarterPlayer > StarterPlayerScripts
Client Controller
-- ClientController
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local player = Players.LocalPlayer
local mouse = player:GetMouse()
local remotes = ReplicatedStorage:WaitForChild("Remotes")
local stealRemote = remotes:WaitForChild("StealLuckyBlock")
local openBlockRemote = remotes:WaitForChild("OpenLuckyBlock")
-- GUI Creation
local screenGui = Instance.new("ScreenGui")
screenGui.Name = "LuckyBlockUI"
screenGui.Parent = player:WaitForChild("PlayerGui")
-- Steal button
local stealButton = Instance.new("TextButton")
stealButton.Size = UDim2.new(0, 200, 0, 50)
stealButton.Position = UDim2.new(0.5, -100, 0.9, -25)
stealButton.Text = "Click Player to Steal!"
stealButton.TextScaled = true
stealButton.BackgroundColor3 = Color3.new(1, 0.5, 0)
stealButton.Parent = screenGui
-- Open block button
local openButton = Instance.new("TextButton")
openButton.Size = UDim2.new(0, 200, 0, 50)
openButton.Position = UDim2.new(0.5, -100, 0.8, -25)
openButton.Text = "Open Lucky Block"
openButton.TextScaled = true
openButton.BackgroundColor3 = Color3.new(0, 1, 0)
openButton.Parent = screenGui
-- Instructions
local instructions = Instance.new("TextLabel")
instructions.Size = UDim2.new(0, 400, 0, 100)
instructions.Position = UDim2.new(0.5, -200, 0, 10)
instructions.Text = "Walk into yellow blocks to collect them!\nSteal from other players!\nOpen blocks for random rewards!"
instructions.TextScaled = true
instructions.BackgroundTransparency = 0.5
instructions.BackgroundColor3 = Color3.new(0, 0, 0)
instructions.TextColor3 = Color3.new(1, 1, 1)
instructions.Parent = screenGui
-- Handle clicking players
mouse.Button1Down:Connect(function()
local target = mouse.Target
if target and target.Parent then
local humanoid = target.Parent:FindFirstChild("Humanoid")
if humanoid then
local targetPlayer = Players:GetPlayerFromCharacter(target.Parent)
if targetPlayer and targetPlayer ~= player then
stealRemote:FireServer(targetPlayer)
end
end
end
end)
-- Open block button
openButton.MouseButton1Click:Connect(function()
openBlockRemote:FireServer()
end)
-- Collect lucky blocks on touch
local character = player.Character or player.CharacterAdded:Wait()
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
RunService.Heartbeat:Connect(function()
local blockFolder = workspace:FindFirstChild("LuckyBlocks")
if blockFolder then
for _, block in ipairs(blockFolder:GetChildren()) do
if block:IsA("Part") then
local distance = (block.Position - humanoidRootPart.Position).Magnitude
if distance < 8 then
block:Destroy()
-- The server will handle adding to inventory
end
end
end
end
end)
-- Highlight players when hovering
local highlight = Instance.new("Highlight")
highlight.FillTransparency = 0.5
highlight.OutlineTransparency = 0
RunService.Heartbeat:Connect(function()
local target = mouse.Target
if target and target.Parent then
local humanoid = target.Parent:FindFirstChild("Humanoid")
if humanoid then
local targetPlayer = Players:GetPlayerFromCharacter(target.Parent)
if targetPlayer and targetPlayer ~= player then
highlight.Parent = target.Parent
highlight.FillColor = Color3.new(1, 0, 0)
return
end
end
end
highlight.Parent = nil
end)
Game Setup Instructions:
- Create a baseplate in Roblox Studio
- Place the GameHandler and LuckyBlockSpawner scripts in ServerScriptService
- Place the ClientController script in StarterPlayer > StarterPlayerScripts
- Set spawn locations around the map
- Optionally add obstacles and decorations
The game features:
- Lucky blocks that spawn randomly around the map
- Players can collect blocks by walking into them
- Steal blocks from other players by clicking on them
- Open blocks for random power-ups (speed, jump, invisibility, etc.)
- Leaderboard showing lucky block count
- Cooldown system to prevent spam stealing
Test the game in Studio with multiple players to see all features in action!