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

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

Asked by 6 years ago
Edited 6 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
Line 1 was cut off. line 1 is game.ReplicatedStorage.CreateEvent.OnServerEvent:Connect(function(player,location)  Gameplay28 139 — 6y
0
math.random apparently uses an old randomization system, try doing math.randomseed(os.time()) at the beginning of your script (it sets the seed to the current time in seconds, shouldn't be the same two servers in a row) User#22604 1 — 6y
0
^ No, not anymore, math.random uses the same random generation as the Random class. SummerEquinox 643 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

Well, one problem I see with what you're doing is that when you go to fire the event, you only pass in the Vector3 argument, but on the server you stipulate two arguments to the function. Therefore, the location's Vector3 value is being passed on to the server as "player" instead of "location."

Try this in the LocalScript on line 5 and see if it works. (Although, I'm not sure why you use the player argument at all)

game.ReplicatedStorage.CreateEvent:FireServer(game.Players.LocalPlayer, Vector3.new(xc,yc,zc))
Ad

Answer this question