text
stringlengths
54
19.6k
begin: How do I use RemoteFunctions to call the server from a client and get a return value in Roblox? solution: --Create RemoteFunction local remoteFunction = Instance.new("RemoteFunction") remoteFunction.Name = "MyRemoteFunction" remoteFunction.Parent = game.ReplicatedStorage --Client calls server and waits for res...
begin: How do I listen to player joining, leaving, and character spawning events in Roblox? output_text: --Player joining Players.PlayerAdded:Connect(function(player) print(player.Name .. " joined!") end) --Player leaving Players.PlayerRemoving:Connect(function(player) print(player.Name .. " left!") end) --Charact...
user: How do I access and modify a player's Humanoid properties like health, speed, and jump power? model: --Get Humanoid local humanoid = character:WaitForChild("Humanoid") --Change health humanoid.Health = 100 --Change walk speed humanoid.WalkSpeed = 16 -- Default is 16 --Change jump power humanoid.JumpPower = 5...
question: How do I detect when a player or object touches a part in Roblox, including with debounce? end: --Basic touch event part.Touched:Connect(function(hit) print("Something touched: " .. hit.Name) end) --Touch with player detection part.Touched:Connect(function(hit) local character = hit.Parent local humanoid...
task: How do I create and configure parts with physics properties in Roblox? output_text: --Create a part local newPart = Instance.new("Part") newPart.Size = Vector3.new(4, 4, 4) newPart.Position = Vector3.new(0, 10, 0) newPart.Anchored = true newPart.Parent = workspace --Part properties part.Anchored = true/false pa...
task: How do I use CFrame to move, rotate, and position parts in Roblox? output_text: --Move part part.CFrame = CFrame.new(0, 10, 0) --Rotate part part.CFrame = CFrame.new(0, 10, 0) * CFrame.Angles(0, math.rad(45), 0) --Look at a position part.CFrame = CFrame.new(part.Position, targetPosition) --Move relative to cu...
input: How do I create, move, and get the position of a Model in Roblox? model: --Create model local model = Instance.new("Model") model.Name = "MyModel" model.Parent = workspace --Set PrimaryPart (required for movement) model.PrimaryPart = partInsideModel --Move model model:PivotTo(CFrame.new(0, 10, 0)) --Get mode...
input: How do I use TweenService to smoothly animate parts in Roblox? end: local TweenService = game:GetService("TweenService") --Create tween local tweenInfo = TweenInfo.new( 2, -- Duration (seconds) Enum.EasingStyle.Linear, -- Easing style Enum.EasingDirection.Out, -- Easing direction 0, -- Repeat count (-1...
question: How do I create, play, and configure sounds in Roblox? end: --Create sound local sound = Instance.new("Sound") sound.SoundId = "rbxassetid://1234567890" -- Replace with actual ID sound.Volume = 1 sound.Parent = workspace --Play sound sound:Play() --Stop sound sound:Stop() --Sound properties sound.Looped ...
query: How do I use ParticleEmitter to create particle effects in Roblox? completion: --Create particle emitter local particles = Instance.new("ParticleEmitter") particles.Parent = part --Particle properties particles.Rate = 10 -- Particles per second particles.Lifetime = NumberRange.new(1, 2) particles.Speed = Numb...
user: How do I cast a ray and detect what it hits in Roblox? model: local rayParams = RaycastParams.new() rayParams.FilterDescendantsInstances = {workspace} rayParams.FilterType = Enum.RaycastFilterType.Exclude --Cast ray local origin = Vector3.new(0, 10, 0) local direction = Vector3.new(0, -20, 0) local result = wor...
task: How do I create teams and assign players to them in Roblox? output_text: local Teams = game:GetService("Teams") --Create team local team = Instance.new("Team") team.Name = "Red Team" team.TeamColor = BrickColor.new("Bright red") team.AutoAssignable = true team.Parent = Teams --Set player team player.Team = tea...
user: How do I create tools, give them to players, and handle equip/unequip events in Roblox? completion: --Create tool local tool = Instance.new("Tool") tool.Name = "Sword" tool.Parent = player.Backpack --Tool equipped tool.Equipped:Connect(function() print("Tool equipped!") end) --Tool unequipped tool.Unequipped:...
start: How do I use BindableEvents to communicate between server-side scripts in Roblox? finish: --Create bindable event local bindable = Instance.new("BindableEvent") bindable.Name = "MyEvent" bindable.Parent = game.ReplicatedStorage --Fire event bindable:Fire("data", 123) --Connect to event bindable.Event:Connect(...
input_text: How do I create and use a ModuleScript in Roblox? answer: --ModuleScript code local Module = {} Module.variable = "Hello" function Module.myFunction() print("Function called!") end return Module --Require module in another script local myModule = require(game.ReplicatedStorage.MyModule) myModule.myFun...
task: What math functions are available in Luau for Roblox scripting? result: --Random numbers local random = Random.new() local num = random:NextInteger(1, 100) local dec = random:NextNumber(0, 1) --Math operations math.abs(-5) -- Returns 5 math.floor(5.7) -- Returns 5 math.ceil(5.2) -- Returns 6 math.sqrt(16) -...
prompt: What string manipulation functions are available in Luau? response: --String length local length = #"Hello" -- Returns 5 --Find substring local found = string.find("Hello World", "World") -- Returns 7 --Get substring local sub = string.sub("Hello", 1, 3) -- Returns "Hel" --Replace local new = string.gsub...
input_text: What are the common table functions in Luau for managing arrays and dictionaries? solution: --Create table local myTable = {"apple", "banana", "orange"} --Add to table table.insert(myTable, "grape") --Remove from table table.remove(myTable, 1) -- Remove first item --Find in table local index = table.fi...
begin: How do I iterate over a dictionary table in Luau? answer: for key, value in pairs(dict) do print(key .. ": " .. tostring(value)) end
input: How do I iterate over an array table in Luau using ipairs? output_text: for index, value in ipairs(myTable) do print(index .. ": " .. value) end
instruction: How do I use time functions and waits in Roblox Luau scripts? solution: --Wait task.wait(1) -- Wait 1 second --Get time local time = os.time() -- Unix timestamp local date = os.date() -- Current date string --Tick (precise time) local startTime = tick() -- do stuff local elapsed = tick() - startTime
query: How do I search for and retrieve parts or objects in the Workspace in Roblox? output_text: --Get all parts local parts = workspace:GetDescendants() --Find by name local part = workspace:FindFirstChild("MyPart") --Find by class local part = workspace:FindFirstChildWhichIsA("Part") --Get children local childre...
input_text: What are the main Roblox game services and how do I access them? response: game:GetService("Players") game:GetService("Workspace") game:GetService("ReplicatedStorage") game:GetService("ServerScriptService") game:GetService("Lighting") game:GetService("SoundService") game:GetService("Teams") game:GetService...
task: How do I control lighting settings like time of day, fog, and brightness in Roblox? output_text: local Lighting = game:GetService("Lighting") --Time of day Lighting.ClockTime = 12 -- Noon (0-24) --Ambient Lighting.Ambient = Color3.new(0.5, 0.5, 0.5) --Brightness Lighting.Brightness = 2 --Fog Lighting.FogEnd...
instruction: How do I run code every frame using RunService in Roblox? finish: local RunService = game:GetService("RunService") --Runs every frame (client) RunService.RenderStepped:Connect(function(deltaTime) print("Frame time: " .. deltaTime) end) --Runs every frame (server) RunService.Heartbeat:Connect(function(d...
query: How do I create a proximity prompt that players can interact with in Roblox? finish: --Create proximity prompt local prompt = Instance.new("ProximityPrompt") prompt.ObjectText = "Press to interact" prompt.ActionText = "Open" prompt.KeyboardKeyCode = Enum.KeyCode.E prompt.Parent = part --Triggered event prompt....
task: How do I detect mouse clicks on a part using ClickDetector in Roblox? result: --Create click detector local clickDetector = Instance.new("ClickDetector") clickDetector.MaxActivationDistance = 10 clickDetector.Parent = part --Mouse click clickDetector.MouseClick:Connect(function(player) print(player.Name .. " c...
instruction: How do I run a function asynchronously in the background in Roblox? end: --Spawn function (runs async) task.spawn(function() while true do print("Running in background") task.wait(1) end end)
start: How do I delay the execution of a function by a set number of seconds in Roblox? solution: --Run after delay task.delay(3, function() print("3 seconds later!") end)
user: How do I handle errors safely using pcall in Luau? output_text: --Safe function call local success, result = pcall(function() return riskyFunction() end) if success then print("Success: " .. result) else warn("Error: " .. result) end
instruction: How do I check the type of a variable in Luau, including Roblox-specific types? response: --Check type type(variable) -- Returns type string typeof(variable) -- Returns Roblox type --Type checking examples type(5) == "number" type("hello") == "string" type(true) == "boolean" type({}) == "table" type(ni...
begin: How do I set and get custom attributes on Instances in Roblox? result: local part = Instance.new("Part") part:SetAttribute("Health", 100) part:SetAttribute("Speed", 16) --Get attribute local health = part:GetAttribute("Health") --Get all attributes local attrs = part:GetAttributes()
input: How do I tag objects and retrieve them using CollectionService in Roblox? completion: local CollectionService = game:GetService("CollectionService") --Add tag CollectionService:AddTag(part, "Interactable") --Get tagged objects local objects = CollectionService:GetTagged("Interactable") --Tag added event Coll...
instruction: How do I create a ScreenGui with frames, labels, and buttons in Roblox? answer: --Create ScreenGui local screenGui = Instance.new("ScreenGui") screenGui.Parent = player.PlayerGui --Create Frame local frame = Instance.new("Frame") frame.Size = UDim2.new(0, 200, 0, 100) frame.Position = UDim2.new(0.5, -100...
input: What are the common properties for configuring GUI elements like UDim2, text, and frames in Roblox? model: --UDim2 (size/position) UDim2.new(0, 100, 0, 50) -- 100 pixels wide, 50 pixels tall UDim2.new(0.5, 0, 0.5, 0) -- Center of screen UDim2.new(1, -20, 1, -20) -- Full screen with 10 pixel margin --Text pr...
user: How do I add rounded corners and a border stroke to UI elements in Roblox? response: --Rounded corners local corner = Instance.new("UICorner") corner.CornerRadius = UDim.new(0, 10) corner.Parent = frame --Border stroke local stroke = Instance.new("UIStroke") stroke.Color = Color3.new(1, 1, 1) stroke.Thickness =...
input: How do I add padding and list/grid layouts to a UI Frame in Roblox? answer: --Padding local padding = Instance.new("UIPadding") padding.PaddingTop = UDim.new(0, 10) padding.PaddingLeft = UDim.new(0, 10) padding.Parent = frame --List layout (vertical) local listLayout = Instance.new("UIListLayout") listLayout.P...
input: How do I create a scrollable frame in Roblox GUI? answer: local scrollFrame = Instance.new("ScrollingFrame") scrollFrame.Size = UDim2.new(0, 200, 0, 300) scrollFrame.CanvasSize = UDim2.new(0, 0, 0, 500) -- Scrollable area scrollFrame.Parent = screenGui
task: How do I display an image inside a Roblox GUI using ImageLabel? output_text: local imageLabel = Instance.new("ImageLabel") imageLabel.Image = "rbxassetid://1234567890" imageLabel.Size = UDim2.new(0, 100, 0, 100) imageLabel.Parent = screenGui
user: How do I create a text input field and read player input in Roblox GUI? finish: local textBox = Instance.new("TextBox") textBox.Size = UDim2.new(0, 200, 0, 30) textBox.PlaceholderText = "Type here..." textBox.Parent = screenGui --Get text when submitted textBox.FocusLost:Connect(function(enterPressed) if enter...
start: How do I load and play animations on a character in Roblox? answer: --Load animation on character local animation = Instance.new("Animation") animation.AnimationId = "rbxassetid://1234567890" local animator = humanoid:WaitForChild("Animator") local track = animator:LoadAnimation(animation) --Play animation tr...
prompt: How do I create and configure a SpawnLocation for players in Roblox? answer: --Create spawn location local spawn = Instance.new("SpawnLocation") spawn.Position = Vector3.new(0, 1, 0) spawn.Anchored = true spawn.Parent = workspace --Set as neutral spawn spawn.Neutral = true --Set team spawn spawn.TeamColor = ...
input_text: How do I build a basic round system with a timer and intermission in Roblox? result: local roundDuration = 60 -- seconds local intermission = 15 -- seconds local inRound = false local function startRound() inRound = true print("Round started!") task.wait(roundDuration) inRound = false print("Round ...
user: How do I create an explosion effect at a position in Roblox? answer: local explosion = Instance.new("Explosion") explosion.Position = Vector3.new(0, 10, 0) explosion.BlastPressure = 100000 explosion.BlastRadius = 10 explosion.DestroyJointRadiusPercent = 0.5 explosion.Parent = workspace
input_text: How do I add a highlight glow effect to a part in Roblox? result: local highlight = Instance.new("Highlight") highlight.FillColor = Color3.new(1, 0, 0) highlight.OutlineColor = Color3.new(1, 1, 1) highlight.FillTransparency = 0.5 highlight.Parent = part
task: How do I add a bloom post-processing effect to the Roblox Lighting? solution: local bloom = Instance.new("BloomEffect") bloom.Intensity = 0.5 bloom.Size = 24 bloom.Threshold = 0.9 bloom.Parent = game.Lighting
user: How do I add a blur effect to the screen in Roblox? completion: local blur = Instance.new("BlurEffect") blur.Size = 10 blur.Parent = game.Lighting
start: How do I use ColorCorrectionEffect to adjust the game's color in Roblox? end: local colorCorrection = Instance.new("ColorCorrectionEffect") colorCorrection.Saturation = 0.2 colorCorrection.Contrast = 0.1 colorCorrection.Brightness = 0.05 colorCorrection.Parent = game.Lighting
user: How do I create an atmosphere with haze and fog in Roblox Lighting? output: local atmosphere = Instance.new("Atmosphere") atmosphere.Density = 0.3 atmosphere.Color = Color3.new(0.8, 0.8, 0.8) atmosphere.Haze = 2 atmosphere.Parent = game.Lighting
input: How do I control the camera's position, type, and field of view using a LocalScript in Roblox? output_text: local camera = workspace.CurrentCamera camera.CameraType = Enum.CameraType.Scriptable camera.CFrame = CFrame.new(0, 50, 50) camera.FieldOfView = 70
question: How do I lerp (linearly interpolate) between two numbers, colors, or vectors in Luau? result: local function lerp(a, b, t) return a + (b - a) * t end local function lerpColor(color1, color2, t) return Color3.new( lerp(color1.R, color2.R, t), lerp(color1.G, color2.G, t), lerp(color1.B, color2.B, t) ...
begin: How do I build a simple inventory system to add, remove, and check items per player in Roblox? response: local inventory = {} local function addItem(player, itemName) if not inventory[player] then inventory[player] = {} end table.insert(inventory[player], itemName) end local function removeItem(player, item...
input: How do I make an NPC follow a player using MoveTo in Roblox? answer: local function followPlayer(npc, targetPlayer) local hrp = npc:FindFirstChild("HumanoidRootPart") local targetChar = targetPlayer.Character if not hrp or not targetChar then return end local targetHrp = targetChar:FindFirstChild("HumanoidR...
task: How do I create a patrolling NPC that moves between waypoints in Roblox? output: local waypoints = {Vector3.new(0, 0, 0), Vector3.new(50, 0, 0), Vector3.new(50, 0, 50)} local currentWaypoint = 1 local function patrol(npc) while true do npc.Humanoid:MoveTo(waypoints[currentWaypoint]) npc.Humanoid.MoveToFini...
begin: How do I build a basic shop system where players can buy items using in-game currency in Roblox? answer: local shopItems = { { name = "Sword", price = 100 }, { name = "Shield", price = 50 }, { name = "Potion", price = 25 } } local function buyItem(player, itemName) for _, item in ipairs(shopItems) do if ...
input_text: How do I create a checkpoint system that tracks and respawns players at their last checkpoint in Roblox? result: local checkpoints = {checkpoint1, checkpoint2, checkpoint3} local playerCheckpoints = {} local function setupCheckpoint(checkpoint, index) checkpoint.Touched:Connect(function(hit) local play...
query: How do I make collectible coins that give players cash when touched in Roblox? output: local coins = workspace.Coins for _, coin in ipairs(coins:GetChildren()) do coin.Touched:Connect(function(hit) local character = hit.Parent local humanoid = character:FindFirstChild("Humanoid") local player = Players:...
prompt: How do I create a door that opens and closes by rotating its CFrame in Roblox? response: local door = workspace.Door local isOpen = false local function toggleDoor() if isOpen then door.CFrame = door.CFrame * CFrame.Angles(0, math.rad(-90), 0) else door.CFrame = door.CFrame * CFrame.Angles(0, math.rad(9...
question: How do I make a part float up and down using a sine wave in Roblox? answer: local function float(part, height, speed) local startY = part.Position.Y task.spawn(function() while part.Parent do part.Position = Vector3.new(part.Position.X, startY + math.sin(tick() * speed) * height, part.Position.Z) t...
instruction: How do I make a part orbit around a center point in Roblox? finish: local function orbit(part, center, radius, speed) task.spawn(function() while part.Parent do local angle = tick() * speed local x = center.X + math.cos(angle) * radius local z = center.Z + math.sin(angle) * radius part.Posi...
instruction: How do I check the distance between two parts and do something when they are close enough in Roblox? output_text: local distance = (part1.Position - part2.Position).Magnitude if distance < 10 then print("Close enough!") end
task: How do I create a countdown timer that prints each second in Roblox? output: local function countdown(seconds) for i = seconds, 1, -1 do print(i) task.wait(1) end print("Time is up!") end
user: How do I use IntValue, StringValue, and BoolValue objects and detect when their value changes in Roblox? output: local intValue = Instance.new("IntValue") intValue.Value = 100 local stringValue = Instance.new("StringValue") stringValue.Value = "Hello" local boolValue = Instance.new("BoolValue") boolValue.Value...
begin: How do I implement pathfinding service in Roblox Luau? answer: local PathfindingService = game:GetService("PathfindingService") local Players = game:GetService("Players") local npc = workspace.NPC local humanoid = npc:WaitForChild("Humanoid") local hrp = npc:WaitForChild("HumanoidRootPart") local path = Pathf...
instruction: How do I implement pathfinding with obstacle recompute in Roblox Luau? response: local PathfindingService = game:GetService("PathfindingService") local npc = workspace.NPC local humanoid = npc.Humanoid local hrp = npc.HumanoidRootPart local path = PathfindingService:CreatePath({ AgentCanJump = true }) l...
input: How do I implement oop with metatables in Roblox Luau? end: -- Define a class local Enemy = {} Enemy.__index = Enemy function Enemy.new(name, health, damage) local self = setmetatable({}, Enemy) self.Name = name self.Health = health self.Damage = damage return self end function Enemy:TakeD...
task: How do I implement oop inheritance in Roblox Luau? answer: local Animal = {} Animal.__index = Animal function Animal.new(name, sound) return setmetatable({ Name = name, Sound = sound }, Animal) end function Animal:Speak() print(self.Name .. " says " .. self.Sound) end -- Subclass local Dog = setmetata...
begin: How do I implement singleton pattern in Roblox Luau? finish: -- Singleton module (only one instance exists) local GameManager = {} GameManager.__index = GameManager local instance = nil function GameManager.getInstance() if not instance then instance = setmetatable({ round = 0, ...
input_text: How do I implement coroutines basics in Roblox Luau? completion: -- Create a coroutine local co = coroutine.create(function(a, b) print("Start:", a, b) coroutine.yield("first yield") print("Resumed!") coroutine.yield("second yield") print("Done!") return "finished" end) -- Run it s...
question: How do I implement producer-consumer with coroutines in Roblox Luau? output: -- Producer generates values, consumer processes them local function producer() local items = {"sword", "shield", "potion", "bow"} for _, item in ipairs(items) do print("Producing: " .. item) coroutine.yield(...
begin: How do I implement network ownership in Roblox Luau? output: -- Server script -- By default server owns all unanchored parts -- Giving ownership to a player reduces lag for that player local part = workspace.MovingPart local Players = game:GetService("Players") -- Give ownership to specific player local funct...
task: How do I implement streaming enabled handling in Roblox Luau? completion: -- LocalScript: safely wait for parts to exist with streaming enabled local function waitForPart(parent, name, timeout) timeout = timeout or 10 local part = parent:FindFirstChild(name) if part then return part end local st...
input: How do I implement tween ui elements in Roblox Luau? finish: local TweenService = game:GetService("TweenService") local frame = script.Parent -- Frame inside ScreenGui local button = frame.OpenButton local tweenInfo = TweenInfo.new(0.4, Enum.EasingStyle.Quart, Enum.EasingDirection.Out) local openTween = Twe...
prompt: How do I implement tween button hover effect in Roblox Luau? output: local TweenService = game:GetService("TweenService") local button = script.Parent local normalSize = UDim2.new(0, 200, 0, 50) local hoverSize = UDim2.new(0, 210, 0, 55) local growTween = TweenService:Create(button, TweenInfo.new(0.15), { ...
input: How do I implement notification ui system in Roblox Luau? solution: -- LocalScript local TweenService = game:GetService("TweenService") local Players = game:GetService("Players") local player = Players.LocalPlayer local gui = player.PlayerGui local function showNotification(message, color) color = color or...
begin: How do I implement character appearance & body color in Roblox Luau? finish: local Players = game:GetService("Players") local function customizeCharacter(character) -- Change body colors local bodyColors = character:FindFirstChild("Body Colors") if bodyColors then bodyColors.HeadColor3 =...
start: How do I implement give accessory to character in Roblox Luau? completion: local function giveHat(character, assetId) local accessory = game:GetService("InsertService"):LoadAsset(assetId) local hat = accessory:FindFirstChildOfClass("Accessory") if hat then hat.Parent = character end ...
instruction: How do I implement resize character in Roblox Luau? output: local function resizeCharacter(character, scale) local humanoid = character:FindFirstChild("Humanoid") if not humanoid then return end -- Use HumanoidDescription for proper scaling local desc = humanoid:GetAppliedDescription() ...
begin: How do I implement basic server-side anti-cheat in Roblox Luau? output_text: -- Server Script: never trust the client local Players = game:GetService("Players") local RunService = game:GetService("RunService") local MAX_SPEED = 30 -- studs/sec threshold local lastPositions = {} Players.PlayerAdded:Connect(fu...
prompt: How do I implement validate remoteevent inputs server-side in Roblox Luau? result: -- NEVER trust data sent from client -- Always validate on server local ReplicatedStorage = game:GetService("ReplicatedStorage") local buyEvent = ReplicatedStorage:WaitForChild("BuyItem") local VALID_ITEMS = { sword = { p...
input_text: How do I implement datastore with retry logic in Roblox Luau? output_text: local DataStoreService = game:GetService("DataStoreService") local Players = game:GetService("Players") local dataStore = DataStoreService:GetDataStore("PlayerData_v2") local MAX_RETRIES = 3 local RETRY_DELAY = 2 local function sa...
input: How do I implement nested datastore save structure in Roblox Luau? output_text: -- Save complex nested data (inventory, stats, settings) local DataStoreService = game:GetService("DataStoreService") local store = DataStoreService:GetDataStore("PlayerData_v3") local DEFAULT_DATA = { stats = { cash ...
query: How do I implement datastore with updateasync (safe concurrent saves) in Roblox Luau? response: local DataStoreService = game:GetService("DataStoreService") local store = DataStoreService:GetDataStore("SafeData") -- UpdateAsync is safer than SetAsync for concurrent updates local function addCurrency(userId, am...
input_text: How do I implement custom signal class in Roblox Luau? model: -- A clean Signal implementation (no BindableEvents needed) local Signal = {} Signal.__index = Signal function Signal.new() return setmetatable({ _listeners = {} }, Signal) end function Signal:Connect(callback) local connection = { cal...
input: How do I implement viewportframe (3d preview in ui) in Roblox Luau? response: -- LocalScript local Players = game:GetService("Players") local player = Players.LocalPlayer local gui = player.PlayerGui local screenGui = Instance.new("ScreenGui") screenGui.Parent = gui -- Create viewport frame local viewport = I...
question: How do I implement surfaceappearance (pbr textures) in Roblox Luau? completion: -- SurfaceAppearance enables PBR (physically based rendering) textures local part = workspace.MyPart local sa = Instance.new("SurfaceAppearance") -- Color / albedo map sa.ColorMap = "rbxassetid://111111111" -- Normal map (surf...
input: How do I implement simple queue matchmaking system in Roblox Luau? answer: local Players = game:GetService("Players") local TeleportService = game:GetService("TeleportService") local GAME_PLACE_ID = 1234567890 local MIN_PLAYERS = 2 local MAX_PLAYERS = 10 local queue = {} local function tryStartMatch() if...
begin: How do I implement party system in Roblox Luau? response: local Players = game:GetService("Players") local parties = {} -- { [leaderId] = { leader, members = {} } } local function createParty(leader) parties[leader.UserId] = { leader = leader, members = { leader } } print(leader.Na...
instruction: How do I implement contextactionservice (mobile + keyboard) in Roblox Luau? response: -- Works on keyboard AND mobile (creates on-screen button) local ContextActionService = game:GetService("ContextActionService") local function onAction(actionName, inputState, inputObject) if inputState == Enum.User...
question: How do I implement mobile touch input detection in Roblox Luau? end: local UserInputService = game:GetService("UserInputService") local Players = game:GetService("Players") local player = Players.LocalPlayer -- Detect if on mobile local isMobile = UserInputService.TouchEnabled and not UserInputService.Keybo...
prompt: How do I implement billboardgui (floating ui above parts) in Roblox Luau? end: -- BillboardGui floats above a part in 3D world space local part = workspace.NPC local billboard = Instance.new("BillboardGui") billboard.Size = UDim2.new(0, 100, 0, 40) billboard.StudsOffset = Vector3.new(0, 3, 0) -- float 3 stud...
question: How do I implement surfacegui (ui painted on part surface) in Roblox Luau? response: -- SurfaceGui renders UI directly on a part's surface local part = workspace.Screen local surfaceGui = Instance.new("SurfaceGui") surfaceGui.Face = Enum.NormalId.Front surfaceGui.PixelsPerStud = 50 surfaceGui.AlwaysOnTop = ...
instruction: How do I implement spring module for smooth camera in Roblox Luau? output_text: -- Spring utility for smooth damped motion local Spring = {} Spring.__index = Spring function Spring.new(initial) return setmetatable({ position = initial, velocity = initial * 0, target = initia...
task: How do I implement head bobbing camera effect in Roblox Luau? output: -- LocalScript: head bobbing while walking local RunService = game:GetService("RunService") local Players = game:GetService("Players") local player = Players.LocalPlayer local camera = workspace.CurrentCamera local bobSpeed = 10 local bobAmo...
begin: How do I implement save player settings with datastore in Roblox Luau? result: local DataStoreService = game:GetService("DataStoreService") local Players = game:GetService("Players") local settingsStore = DataStoreService:GetDataStore("PlayerSettings") local DEFAULT_SETTINGS = { musicVolume = 0.5, sfxV...
question: How do I implement hitbox combat system in Roblox Luau? result: -- Server Script local Players = game:GetService("Players") local function getHumanoid(part) local char = part.Parent return char:FindFirstChild("Humanoid"), char end local function createHitbox(attacker, size, offset, damage, duration...
input: How do I implement knockback effect in Roblox Luau? response: -- Server Script local function applyKnockback(character, direction, force) local hrp = character:FindFirstChild("HumanoidRootPart") if not hrp then return end -- Disable default physics briefly hrp.AssemblyLinearVelocity = Vector3.n...
user: How do I implement status effects system (burn, slow, stun) in Roblox Luau? solution: local statusEffects = {} local function applyEffect(character, effectName, duration, callback) local humanoid = character:FindFirstChild("Humanoid") if not humanoid then return end local id = character.Name .. eff...
start: How do I implement game state machine in Roblox Luau? answer: local States = { LOBBY = "Lobby", INTERMISSION = "Intermission", PLAYING = "Playing", ENDED = "Ended" } local GameState = {} GameState.__index = GameState function GameState.new() return setmetatable({ cu...
begin: How do I implement procedural map generation in Roblox Luau? output_text: -- Simple grid-based procedural map local function generateMap(width, height, seed) math.randomseed(seed or os.time()) local map = {} for x = 1, width do map[x] = {} for z = 1, height do local roll...