Model doesn't move when script tells it to

local GroupId = 5162592
local AllowedRank = 103
local Room = game.ReplicatedStorage.RoomsForTrainings.BaristaTrainingRoom:Clone()
game.Players.PlayerAdded:Connect(function(Player)
	Player.Chatted:Connect(function(chat)
		if chat =="!room Barista" and Player:GetRankInGroup(GroupId) >= AllowedRank then
			Room.Parent = game.Workspace
			Room.FunctionalProperties.TeleSpawn.Position = Vector3.new(Random.new(1000,1000000), Random.new(1000,1000000), Random.new(1000,1000000))
			
			else
		end
	end)
end)

The context:

I’m trying to make a script that will clone a model from replicated storage, then place it in a random position in the workspace.

The issue:

It only clones once, and always in the same place.

What I think went wrong;
I’m genuinely blank here.

It’s because you only made one clone at the beginning of the script
Try this:

local GroupId = 5162592
local AllowedRank = 103

game.Players.PlayerAdded:Connect(function(Player)
	Player.Chatted:Connect(function(chat)
		if chat =="!room Barista" and Player:GetRankInGroup(GroupId) >= AllowedRank then
local Room = game.ReplicatedStorage.RoomsForTrainings.BaristaTrainingRoom:Clone()
			Room.Parent = game.Workspace
			Room.FunctionalProperties.TeleSpawn.Position = Vector3.new(Random.new(1000,1000000), Random.new(1000,1000000), Random.new(1000,1000000))
			
			else
		end
	end)
end)

For the problem of it being in the same place, I honestly have no clue sorry. Also noticed you are only moving the telespawn and not the whole room. Why is that?

1 Like

Because that’s it’s primary part.

I see. Well, I really don’t know why it wouldn’t work.

If someone can figure out the positioning issue, PLEASE DO.

Well, the way you randomize the location is wrong.

WRONG WAY

Vector3.new(Random.new(1000,1000000), Random.new(1000, 100000), Random.new(1000, 100000))

You should use math.random() instead.

Also, you should be cloning a new barista model every time someone called the command instead of just referring the same model over and over again.

1 Like

Didn’t work, model remains in same position.

Moving a PrimaryPart alone won’t work. You’re going to want to call :PivotTo() on the model.

Example if the room is a model:

Room:PivotTo(CFrame.new(math.random(1000,1000000),math.random(1000,1000000),math.random(1000,1000000))
1 Like

try this! i probaly will work, not sure!

if Player:GetRankInGroup(GroupId) >= AllowedRank then
    Player.Chatted:Connect(funtion(chat)
      -- Rest of the Code
    end)
end

change this to math.random to randomize a number.

local Players = game:GetService("Players")
local Replicated = game:GetService("ReplicatedStorage")
local Rooms = Replicated.RoomsForTrainings
local Room = Rooms.BaristaTrainingRoom

local GroupId = 5162592
local RequiredRank = 103

Players.PlayerAdded:Connect(function(Player)
	Player.Chatted:Connect(function(Message)
		if Message:lower() == "!room barista" then
			local Succ, Res = pcall(function()
				return Player:GetRankInGroup(GroupId)
			end)
			
			if Succ then
				if Res then
					if Res >= RequiredRank then
						local RoomClone = Room:Clone()
						Room.FunctionalProperties.TeleSpawn.Position = Vector3.new(math.random(1000, 1000000), math.random(1000, 1000000), math.random(1000, 1000000))
					end
				end
			else
				warn(Res)
			end
		end
	end)
end)
1 Like