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

How does Random Relative Positions work?

Asked by 7 years ago
Edited 7 years ago

So in a script I have a fire ball being launched through the torso, now this fire ball is being shot out like a firestorm but I don't want it to be in the same place every time or else it'll look like a laser beam.

local xPosition = handle.Position+math.random(-2,2)
local yPosition = handle.Position+math.random(-1,3)

so I had this done, it doesn't work obviously, handle represents the humanoid torso and I'm using Cframe for the starting position of said fireball seen here.

        local p = Instance.new("Part")
        p.CFrame = CFrame.new(xPosition,yPosition,1)
        p.TopSurface = "Smooth" 
        p.BottomSurface = "Smooth" 
        p.Shape = Enum.PartType.Ball 
        p.Size = Vector3.new(1, 1, 1) 
        p.Transparency = (0.5)
        p.CanCollide = false
        p.Material = "Neon"
        p.BrickColor = BrickColor.new("Toothpaste")
        p.Parent = ws

How do I make it so that the part is spawned in randomly on the X and Y coordinates relative to humanoid torso?

vvvv This works but it's in one constant line vvvv

        local p = Instance.new("Part")
        p.CFrame = CFrame.new(handle.Position)
        p.TopSurface = "Smooth" 
        p.BottomSurface = "Smooth" 
        p.Shape = Enum.PartType.Ball 
        p.Size = Vector3.new(1, 1, 1) 
        p.Transparency = (0.5)
        p.CanCollide = false
        p.Material = "Neon"
        p.BrickColor = BrickColor.new("Toothpaste")
        p.Parent = ws

Help would be very much appreciated!!

Answer this question