Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 3 years ago
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

Log in to vote
1
Answered by 3 years ago

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)
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 pepsymax 73 — 3y
1
put the x, y, z before local part greatneil80 2647 — 3y
0
Yeah, that would work just put lines 2 through 4 below line 7 KripticalYT 100 — 3y
Ad
Log in to vote
0
Answered by 3 years ago
--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)

Answer this question