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

Random Spawning for Players in a Script. How to do this?

Asked by 5 years ago

I've got this script:

`function onTouched(m)
    p = m.Parent:findFirstChild("Humanoid")
    if p ~= nil then
        p.Torso.CFrame = CFrame.new(0,-10,13644) --Change the numbers here to the position you want the humanoid to teleport to.
    end
end
script.Parent.Touched:connect(onTouched)

I want to make it randomly spawn Players that touch the brick and when they spawn they go to a random spot in a selected area. Any ideas on how to do this?

`

0
:findFirstChild() and :connect is decaperated, instead use :FindFirstChild() and :Connect User#23365 30 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

Maybe you could try something like this?


function onTouched(m) p = m.Parent:findFirstChild("Humanoid") if p ~= nil then local x = math.random(-10,10) --Specifies range for what the x coordinate can be local y = math.random(0,10) --Specifies range for what the y coordinate can be local z = math.random(-10,10) --Specifies range for what the z coordinate can be print(x) print(y) print(z) p.Torso.CFrame = CFrame.new(x,y,z) --Change the numbers here to the position you want the humanoid to teleport to. end end script.Parent.Touched:connect(onTouched)
Ad

Answer this question