My script just stop when trying to positioned the model

I tried to make a storm spawning and despawning script but its getting stuck at
Clone.PrimaryPart.Position.X = math.random(-1000,1000)
Cuplikan layar 2024-08-23 212019
After Changing the clone parent.

I tried adding workspace:WaitForChild(tostring(Clone)) But that dosent to work either

This is the script VVV (Storm is a model and Car1 is the tornado)

local storm = game:GetService("ServerStorage"):WaitForChild("Storm")
repeat
	local rng1 = math.random(10,11)
	local rng2 = math.random(60,120)
	wait(rng1)
	local Clone = storm:Clone()
	Clone.Parent = game.workspace
	workspace:WaitForChild(tostring(Clone))
	Clone.PrimaryPart.Position.X = math.random(-1000,1000)
	Clone.PrimaryPart.Position.Z = math.random(-1000,1000)
	Clone.Car1.F.Value = math.random(0,5)
	Clone.Car1.BodyVelocity.Velocity.X = math.random(-50,50)
	Clone.Car1.BodyVelocity.Velocity.Z = math.random(-50,50)
	wait(rng2)
	Clone:Destroy()
until false

This is the Car1
Cuplikan layar 2024-08-23 212413

Anyone seems to know whats the problem?

Can you explain more? I don’t think I understand.

You cannot assign values to Vector3s components
Create another Vector3 and assign it to the Position / Velocity instead of assigning each component seperately
Something like this

local storm = game:GetService("ServerStorage"):WaitForChild("Storm")
repeat
	local rng1 = math.random(10,11)
	local rng2 = math.random(60,120)
	wait(rng1)
	local Clone = storm:Clone()
	Clone.Parent = game.workspace
	Clone.PrimaryPart.Position = Vector3.new(math.random(-1000,1000), Clone.PrimaryPart.Position.Y, math.random(-1000,1000))
	Clone.Car1.F.Value = math.random(0,5)
	Clone.Car1.BodyVelocity.Velocity = Vector3.new(math.random(-50,50), Clone.Car1.BodyVelocity.Velocity.Y, math.random(-50,50))
	wait(rng2)
	Clone:Destroy()
until false
1 Like

You have to set the velocity as a whole I think

clone.Car1.PrimaryPart.Position = Vector3.new(math. Random(-1000,1000),0,math.random(-1000,1000))
-- Also you cant apply body velocity to a model
clone.Car1.PrimaryPart.BodyVelocity.Velocity = Vector3.new(math. Random(--50,50),0,math.random(-50,50))

Lol i also refactored his code to get a better understanding

local storm = game:GetService("ServerStorage"):WaitForChild("Storm")

repeat
	local random1 = math.random(10,11)
	local random2 = math.random(60,120)
	
	wait(random1)
	
	local stormClone = storm:Clone() -- is this anchored?
	local cloneRoot = stormClone.PrimaryPart
	local cloneCar = stormClone.Car1
	
	stormClone.Parent = game.workspace
	
	cloneRoot.Position = Vector3.new(math.random(-1000,1000),cloneRoot.Position.Y,math.random(-1000,1000))
	
	cloneCar.F.Value = math.random(0,5) -- when experiencing problems never shorten variable names
	
	cloneCar.BodyVelocity.MaxForce = Vector3.one * math.huge
	cloneCar.BodyVelocity.Velocity = Vector3.new(math.random(-50,50),0,math.random(-50,50))
	
	wait(random2) -- u can also use game:GetService("Debris"):AddItem(stormClone, random2)
	stormClone:Destroy()
until false
1 Like

Ty now its working now and i will also improve my forum so its more understandable
Catsronomical’s Script also work but with little adjustment

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.