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

Why is it not spawning where I want it? (cloned object)

Asked by 4 years ago
01local Clickd = script.Parent.ClickDetector
02local Button = script.Parent
03local RS = game:GetService("ReplicatedStorage")
04local EndFolder = RS:WaitForChild("End")
05local Pillar = EndFolder.Pillar
06local Radius = 100
07local X = math.random(0,Radius)
08local Y = 0
09local Z = math.random(0,Radius)
10 
11 
12Clickd.MouseClick:Connect(function()
13    local ClonedPillar = Pillar:Clone()
14    ClonedPillar.Parent = workspace
15    ClonedPillar.Position = Vector3.new(X,Y,Z)
View all 21 lines...

My cloned object is not spawning where I want it to, I've tried this with many other scripts and it doesn't work, one with an instance, the "Explosion" instance spawns at the middle of the baseplate. While the current script here spawns at one position, nothing else

0
Where do you want it to spawn? LeedleLeeRocket 1257 — 4y
0
You wanted a random position for X and Z, or? R4nd0ml0l2 105 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

Hi! Your code is choosing a number between 0 and 100 for once. To fix this, you simply can do a loop for the values X and Z. Heres a possible result:

01local Clicked = script.Parent.ClickDetector
02local Button = script.Parent
03local RS = game:GetService("ReplicatedStorage")
04local EndFolder = RS:WaitForChild("End")
05local Pillar = EndFolder.Pillar
06local Radius = 100
07local X -- Nill value.
08local Y = 0
09local Z -- Nill value.
10 
11Clicked.MouseClick:Connect(function()
12    print("work")
13    local ClonedPillar = Pillar:Clone()
14    ClonedPillar.Parent = workspace
15    ClonedPillar.CFrame = CFrame.new(X,Y,Z)
View all 22 lines...

It'll simply just generate a number every 0.03 seconds and if you click on the part, you can see it randomly generates to the given coordinates! If it doesn't work, then you can ask why it doesn't and what the error is. Have a good day!

0
thanks it worked! RandyN56 23 — 4y
Ad

Answer this question