Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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?

`

1 comment

0

:findFirstChild() and :connect is decaperated, instead use :FindFirstChild() and :Connect

1 answer

✓ Accepted answer

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.