So I made a new game and I try to use hazard to make players die and the hazard place on the random grid. But the problem is I have 2 hazards (the first hazard changed position correctly except for the second hazard which uses same code as the first hazard)
The code worked with no error but the second hazard doesn't change position even with the same code as the first hazard, unlike the first hazard which changes position. I expect the second hazard to change position like the first hazard and here is the code.
Also, I use the server script because the hazard required to replicate to all servers and I use the "Play"mode.
local storeRandom = "" local recentRandomized = false local h = "" while true do wait(3) local function random() storeRandom = math.random(1,16) if workspace.PlayGrid["Grid"..storeRandom].ActiveValue.Value == true then random() else recentRandomized = true end end if recentRandomized == false then random() end workspace.PlayGrid["Grid"..storeRandom].SelectionBox.Visible = true wait(1) local gridPosX = workspace.PlayGrid["Grid"..storeRandom].Position.X local gridPosY = workspace.PlayGrid["Grid"..storeRandom].Position.Y local gridPosZ = workspace.PlayGrid["Grid"..storeRandom].Position.Z workspace.PlayGrid["Grid"..storeRandom].SelectionBox.Visible = false h = math.random(1,2) local hazards = game.ServerStorage:WaitForChild("Hazard"..h) local hazard = hazards:Clone() if h == 1 then hazard.Parent = workspace.PlayGrid["Grid"..storeRandom] hazard:SetPrimaryPartCFrame(CFrame.new(gridPosX, gridPosY + 2.5, gridPosZ) * CFrame.Angles(math.pi, math.pi/2, math.pi)) else hazard.Parent = workspace.PlayGrid["Grid"..storeRandom] hazard:SetPrimaryPartCFrame(CFrame.new(gridPosX, gridPosY + 2.5, gridPosZ) * CFrame.Angles(math.pi, math.pi/2, math.pi)) -- This code have a problem end recentRandomized = false workspace.PlayGrid["Grid"..storeRandom].ActiveValue.Value = true end
Here is the video (download required): https://cdn.discordapp.com/attachments/678090587664023562/697299004802990110/robloxapp-20200408-1115282.wmv
The first Hazard is Spike
The second Hazard is Lava
Make sure the model is anchored, and that a primary part is set for both models