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

Why are all of these parts spawning in the same place?

Asked by 5 years ago

Server script.

game.ReplicatedStorage.CreateEvent.OnServerEvent:Connect(function(player,location)
    print("Works!")
    for i = 1, (tonumber(9)) do
    wait(0.2)
game.Lighting.F9.Position = location
local deathPart = game.Lighting.F9
wait(0.2)
F9C = deathPart:Clone()
wait(0.2)
F9C.Parent = game.workspace
F9C.Position = location
end
end)

Local script.

script.Parent.MouseButton1Click:Connect(function()
xc = math.random(-590,-460)
yc = 57
zc = math.random(-170, 60)
    game.ReplicatedStorage.CreateEvent:FireServer(Vector3.new(xc,yc,zc))
end)

The parts' location will be random but they all spawn in the same random place. How do I make each of them spawn in a different place?

0
Lighting totally makes sense as a storage location. Especially when we have things like ServerStorage and ReplicatedStorage. Lighting is clearly the way to go. User#25115 0 — 5y
0
bad, no TheeDeathCaster 2368 — 5y

1 answer

Log in to vote
0
Answered by
LeadRDRK 437 Moderation Voter
5 years ago

In the LocalScript, you generated a random Vector3, yet in the server, you used that same Vector3 for every single part that was created. The solution here is to not generate the Vector3 on client but generate it on the server for each and every part that is going to be created.

game.ReplicatedStorage.CreateEvent.OnServerEvent:Connect(function(player)
    print("Works!")
    for i = 1, 9 do
    wait(0.2)
game.Lighting.F9.Position = location
local deathPart = game.Lighting.F9
wait(0.2)
local F9C = deathPart:Clone()
wait(0.2)
F9C.Parent = game.workspace
F9C.Position = Vector3.new(math.random(-590,-460), 57, math.random(-170,-60))
end
end)

Also I recommend you to store your part in ReplicatedStorage instead, Lighting is clearly not for the purpose of storing stuff.

Ad

Answer this question