I am currently working on a project, I already know how to spawn in random things using math.random but I want to know how I could make them randomly spawn in different spots but they keep their Y value.
I am using a ProximityPrompt to do all this, here is an image:
I want to make the part spawn in random positions each time the Prompt is triggered and I also want to make the part keep its Y value to 10 instead of changing it. I would like to do this because I will later make Models or NPC’s spawn in when the Prompt Triggers, I am currently trying to figure out how this would work.
Here is the Script I am using in ServerScriptService:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")
local Button = game:GetService("Workspace"):WaitForChild("Button")
local Prompt = Button.Button.PromptAttachment:WaitForChild("ProximityPrompt")
local Sounds = Button:WaitForChild("Sounds")
local Events = ServerStorage:WaitForChild("Events"):GetChildren()
Prompt.Triggered:Connect(function()
Sounds.Press1:Play()
local ClonedEvent = Events[math.random(1, #Events)]:Clone()
ClonedEvent.Parent = workspace.Spawned
print("Spawned " .. ClonedEvent.Name)
end)
I couldn’t really find any posts related to my problem, but I thought about putting in Number Values in the parts or models, and then the script would find these values and use them, but I think it would be too complicated to script.
What do I do?