Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I make it so everytime someone chats a new part becomes a random position?

local pos1 = {250, 0, 250}
local pos2 = {-250, 0, -250}
game.Players.PlayerAdded:Connect(function(plr)
	plr.Chatted:Connect(function()
		local part = Instance.new("Part", game.Workspace)
		part.Anchored = true
		part.Position = Vector3.new(math.random(#pos1, #pos2))
	end)
end)

I am struggling please help.

2 answers

✓ Accepted answer

This should work

--Must go from low to high
x = math.random(0,100)
y = math.random(0,100)
z = math.random(0,100)

game.Players.PlayerAdded:Connect(function(Player)
    Player.Chatted:Connect(function()
        local part = Instance.new("Part", game.Workspace)
        part.Anchored = true
        part.Position = Vector3.new(x,y,z)
    end)
end)

3 comments

0

The positions work but how can I make it so every time it's a different position because when I test it, it creates a random position but spawns in the same position

1

put the x, y, z before local part

0

Yeah, that would work just put lines 2 through 4 below line 7

--pos1 dictionary--
local pos1 = 
{
250,
 0,
 250
}
--pos2 dictionary--
local pos2 =
{
-250,
 0,
-250
}
game.Players.PlayerAdded:Connect(function(plr) --when player chats
    plr.Chatted:Connect(function()
        local part = Instance.new("Part", game.Workspace) -- new part created to workspace--
        part.Anchored = true
        part.Position = Vector3.new(math.random(pos2[1], pos1[1]), math.random(pos1[2], pos2[2]), math.random(pos2[3], pos1[3])) --first argument is the X axis (also the math.random goes to lowest to highest like how KripticalYT said), second argumest is the Y axis, the third one is the Z axis.--
    end)
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.