You can write your topic however you want, but you need to answer these questions:
- What do you want to achieve? Keep it simple and clear!
I have a game that has a treasure hunt event in Roblox which works by randomly spawning a gold treasure part at specified locations every five minutes. Each treasure remains visible for 30 seconds and features a label that says “Treasure!” above it.
-
What is the issue? Include screenshots / videos if possible!
i was hoping this script will work, but it seems that i did a somewhat mistake. and the script even breaks sometimes. in the output -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
i couldn’t really find something similar, nor do i know what’s causing this. its in a script in serverscriptservice.
if any of you have suggestions, please let me know
Script:
local Players = game:GetService("Players")
local TweenService = game:GetService("TweenService")
local treasureLocations = {
Vector3.new(10, 0, 20),
Vector3.new(-15, 0, -30),
Vector3.new(5, 0, 40),
}
local function spawnTreasure()
local randomLocation = treasureLocations[math.random(1, #treasureLocations)]
local treasure = Instance.new("Part")
treasure.Size = Vector3.new(2, 2, 2)
treasure.Position = randomLocation
treasure.Anchored = true
treasure.BrickColor = BrickColor.new("Gold")
treasure.Parent = workspace
local treasureLabel = Instance.new("BillboardGui", treasure)
treasureLabel.Size = UDim2.new(0, 100, 0, 50)
treasureLabel.Adornee = treasure
local labelText = Instance.new("TextLabel", treasureLabel)
labelText.Text = "Treasure!"
labelText.Size = UDim2.new(1, 0, 1, 0)
labelText.BackgroundTransparency = 1
wait(30)
treasure:Destroy()
end
local function startEvent()
while true do
spawnTreasure()
wait(300)
end
end
startEvent()