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’m making a game with randomized maps, each of which having their corresponding tools folder in replicated storage. The maps are picked via module script, and fired from a proximity prompt via server script. -
What is the issue? Include screenshots / videos if possible!
When I enter a map, the map loads, but I don’t get the tools. -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I asked chatGPT (countless time)
ServerScript
local MapModule = require(game:GetService("ServerScriptService").MapModule)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local MapsLoaded = 0
local Plots = workspace.Plots
local function typeText(text, Object, Interval, lifetime)
-- Type the text
for i = 1, #text do
Object.Text = string.sub(text, 1, i)
task.wait(Interval)
end
-- Wait before starting to backspace
task.wait(lifetime)
-- Backspace the text
for i = #text, 1, -1 do
Object.Text = string.sub(text, 1, i - 1)
task.wait(Interval)
end
end
script.Parent.ProximityPrompt.Triggered:Connect(function(plr)
script.Parent.ProximityPrompt.Enabled = false
local playerGui = plr:FindFirstChild("PlayerGui")
if not playerGui then return end
-- Create UI
local screenGui = Instance.new("ScreenGui")
screenGui.IgnoreGuiInset = true
screenGui.Parent = playerGui
local frame = Instance.new("Frame")
frame.Size = UDim2.new(1, 0, 1, 0) -- Fullscreen fade
frame.Position = UDim2.new(0, 0, 0, 0)
frame.BackgroundTransparency = 1
frame.BackgroundColor3 = Color3.new(0, 0, 0)
frame.Parent = screenGui
local TextLabel = Instance.new("TextLabel")
TextLabel.Parent = frame
TextLabel.Size = UDim2.new(0.5, 0, 0.1, 0)
TextLabel.Position = UDim2.new(0.25, 0, 0.4, 0)
TextLabel.BackgroundTransparency = 1
TextLabel.TextColor3 = Color3.new(1, 1, 1)
TextLabel.TextScaled = true
TextLabel.TextStrokeTransparency = 1
TextLabel.TextWrapped = true
TextLabel.Font = Enum.Font.Ubuntu
typeText("You dream of a place named...", TextLabel, 0.1, 1)
task.wait(1.5)
-- Tween animation
local tweenService = game:GetService("TweenService")
local fadeIn = tweenService:Create(frame, TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.Out), {BackgroundTransparency = 0})
local fadeOut = tweenService:Create(frame, TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.Out), {BackgroundTransparency = 1})
-- Fade in
fadeIn:Play()
task.wait(1.5)
-- Ensure character is valid before teleporting
if plr.Character and plr.Character:FindFirstChild("HumanoidRootPart") then
local Map = MapModule:PickMap()
if Map and Map.Object and Map.SpawnPoint then
typeText(Map.Name, TextLabel, 0.1, 1.5)
MapsLoaded += 1
local NewMap = Map.Object
local Plot = Plots:FindFirstChild("Plot" .. MapsLoaded)
if Plot then
NewMap.Parent = Plot
plr.PlotStats.PlotNumber.Value = MapsLoaded
NewMap:MoveTo(Plot.Position)
else
warn("No available plot found!")
end
-- Teleport player
plr.Character:MoveTo(NewMap.SpawnPoint.Position)
for _, tool in Map.Tools:GetChildren() do
tool.Parent = plr.Backpack
end
else
warn("Invalid Map: Map.Object or Map.SpawnPoint is missing!")
end
end
task.wait(0.5)
-- Fade out
fadeOut:Play()
fadeOut.Completed:Wait() -- Ensures fade out finishes before destruction
screenGui:Destroy()
script.Parent.ProximityPrompt.Enabled = true
end)
ModuleScript
--// Services \\--
local RepStore = game:GetService("ReplicatedStorage")
--// Folders \\--
local MapFolder = RepStore:WaitForChild("Maps")
-- Ensure randomness
math.randomseed(tick())
local MapModule = {}
local Maps = {
FracturedCrossroads = {
Name = "Fractured Crossroads",
Object = MapFolder.Crossroad,
SpawnPoint = MapFolder.Crossroad.SpawnPoint,
Tools = RepStore.MapTools.Crossroads
},
SkibidiCrossroads = {
Name = "Skibidi Crossroads",
Object = MapFolder.SkibidiCrossroads,
SpawnPoint = MapFolder.SkibidiCrossroads.SpawnPoint,
Tools = RepStore.MapTools.Crossroads
}
}
function MapModule:GivePlotStats(plr)
local Folder = Instance.new("Folder", plr)
Folder.Name = "PlotStats"
local PlotNo = Instance.new("NumberValue", Folder)
PlotNo.Name = "PlotNumber"
PlotNo.Value = 0
end
function MapModule:PickMap()
-- Extract keys into an array
local mapKeys = {}
for key in pairs(Maps) do
table.insert(mapKeys, key)
end
-- Pick a random key
local RandomIndex = math.random(1, #mapKeys)
local PickedMap = Maps[mapKeys[RandomIndex]]
-- Clone the selected map to ensure uniqueness
local NewMap = PickedMap.Object:Clone()
NewMap.Parent = workspace -- Adjust as needed
-- Find SpawnPoint in the cloned map
local SpawnPoint = NewMap:FindFirstChild("SpawnPoint") or PickedMap.SpawnPoint
return {
Name = PickedMap.Name,
Object = NewMap,
SpawnPoint = SpawnPoint
}
end
return MapModule