#random Position

1 messages · Page 1 of 1 (latest)

gentle elbow
#

i'm trying to spawn a killbrick in a certain area but it isn't working .

local Rs = game:GetService("ReplicatedStorage")
local damagepart =Rs.damage
local cooldown = false
local plate = game.Workspace.plate.CFrame
local X,Y,Z = plate.X , plate.Y , plate.Z
local debris = game:GetService("Debris")
while true do 
    local clone =damagepart:Clone()
    clone.Parent = game.Workspace
    clone.CFrame = CFrame.new(math.random(0-X,X),0.5,math.random(0-X,X))*plate
    task.wait(0.2)
    debris:AddItem(clone,10)


clone.Touched:Connect(function(hit)
    local player = hit.Parent:FindFirstChild("Humanoid")
    if player and not cooldown then 
        cooldown = true
        player.Health = 0
    end
    cooldown = false
    end)
end
#

So the random Position isn't working

umbral skiff
#

You're using X for both the X & Z axis

gentle elbow
#

oh yeah true

#

still isn't working

#

Workspace.Script:10: invalid argument #2 to 'random' (interval is empty)

umbral skiff
gentle elbow
#

yes

umbral skiff
gentle elbow
#

oh

#

-1.5

umbral skiff
#

0 - -1.5 = 1.5
so 1.5 min -1.5 max is an invalid range.

The random should be of the size of the plate, not position

gentle elbow
#

oh ok

#

Im trying to fix it

umbral skiff
#

Also, to make things negative you don't have to do 0 - X, you can just do -X

gentle elbow
#

thx for the tipp

#

I fixed it

#

now I have another problem

umbral skiff
gentle elbow
#

they don't always spawn on the plate

umbral skiff
gentle elbow
#

here is the new code

umbral skiff
# gentle elbow here is the new code

If the X position is at 500, but the size of the plate is only 10, then you'll be spawning things at a range of -500 to 500.

You need to make the range out of the size, not position. So you'd do position + the random size number.

Taking into account the origin of parts is at the center, not top left.

gentle elbow
#

thx for the help fixed it

tame pulsar
#

oop

gentle elbow