Randomizing Part Spawn, depends on player spawn

  1. What do you want to achieve? Keep it simple and clear!
    So, basically i can’t randomize part spawn in depends of player , it just spawn in same pos
  2. What is the issue? Include screenshots / videos if possible!
    Idk why it don’t works
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub? I was using a tons of math.random solutions, but this just bring to spawn in same position as before

My code:

local RS = game:GetService("ReplicatedStorage")
local WoodLev1 = RS.WoodLev1
local RaftPos = game.Workspace:WaitForChild("StarterRaft").Part
local RaftPosX = RaftPos.Position.X
local RaftPosY = RaftPos.Position.Y
	while true do
	PosX = math.random(RaftPosX, RaftPosX + 50)
	PosY = math.random(RaftPosY, RaftPosY + 50)
	local WoodLev1Clone = WoodLev1:Clone()
WoodLev1Clone.Parent = game.Workspace.MaterialFolder
	WoodLev1Clone.Part.Position = Vector3.new(RaftPosX, 26, RaftPosY)
	wait(2)
end

Why don’t you use LocalScript?

Problem in other, parts just spawn in same position

Uhm… Maybe you should set locations.

in Explorer:
image

Put Folder at SeverStorage.
You can set Location like:

local LocationsFolder = game.ServerStorage.Folder
local ChosenLocation = LocationsFolder[math.random(1, #LocationsFolder:GetChildren())]

It’s probably using the same random seed. Often in my projects studio would for some reason default to the same seed causing the exact same pattern over and over. To fix this either use the random object or set the randomseed at the start

local rand = Random.new()
local RS = game:GetService("ReplicatedStorage")
local WoodLev1 = RS.WoodLev1
local RaftPos = game.Workspace:WaitForChild("StarterRaft").Part
local RaftPosX = RaftPos.Position.X
local RaftPosY = RaftPos.Position.Y
	while true do
	PosX = rand:NextNumber(RaftPosX, RaftPosX + 50)
	PosY = rand:NextNumber(RaftPosY, RaftPosY + 50)
	local WoodLev1Clone = WoodLev1:Clone()
WoodLev1Clone.Parent = game.Workspace.MaterialFolder
	WoodLev1Clone.Part.Position = Vector3.new(RaftPosX, 26, RaftPosY)
	wait(2)
end

Or if you prefer

math.randomseed(tick())
local RS = game:GetService("ReplicatedStorage")
local WoodLev1 = RS.WoodLev1
local RaftPos = game.Workspace:WaitForChild("StarterRaft").Part
local RaftPosX = RaftPos.Position.X
local RaftPosY = RaftPos.Position.Y
	while true do
	PosX = math.random(RaftPosX, RaftPosX + 50)
	PosY = math.random(RaftPosY, RaftPosY + 50)
	local WoodLev1Clone = WoodLev1:Clone()
WoodLev1Clone.Parent = game.Workspace.MaterialFolder
	WoodLev1Clone.Part.Position = Vector3.new(RaftPosX, 26, RaftPosY)
	wait(2)
end

You’re not using your randomized PosX and PosY, you’re using RaftPosX and RaftPosY.

local RS = game:GetService("ReplicatedStorage")
local WoodLev1 = RS.WoodLev1
local RaftPos = game.Workspace:WaitForChild("StarterRaft").Part
local RaftPosX = RaftPos.Position.X
local RaftPosY = RaftPos.Position.Y
	while true do
	PosX = math.random(RaftPosX, RaftPosX + 50)
	PosY = math.random(RaftPosY, RaftPosY + 50)
	local WoodLev1Clone = WoodLev1:Clone()
WoodLev1Clone.Parent = game.Workspace.MaterialFolder
	WoodLev1Clone.Part.Position = Vector3.new(PosX, 26, PosY)
	wait(2)
end

This will work hopefully!

Also – not sure if you meant to do this but you’re randomizing based off of the Y axis, but then when you set the position you’re using 26 on the y-axis constantly. This leads me to believe you meant for the z-axis! I also quickly tried to fix this for you if it isn’t what you intended!

local RS = game:GetService("ReplicatedStorage")
local WoodLev1 = RS.WoodLev1
local RaftPos = game.Workspace:WaitForChild("StarterRaft").Part
local RaftPosX = RaftPos.Position.X
local RaftPosZ = RaftPos.Position.Z
	while true do
	PosX = math.random(RaftPosX, RaftPosX + 50)
	PosZ = math.random(RaftPosZ, RaftPosZ + 50)
	local WoodLev1Clone = WoodLev1:Clone()
WoodLev1Clone.Parent = game.Workspace.MaterialFolder
	WoodLev1Clone.Part.Position = Vector3.new(PosX, 26, PosZ)
	wait(2)
end

That Works thanks! 30 lettersssssss