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

Random teleportation malfunction?

I made a script that teleports you to a certain brick depending on a number generated by math.random. However, this particular script only seems to transport me to the destination denoted by number 3. Here is the script.

function transport()
	math.randomseed(tick())
	local num = math.random(1,4)
	wait()
	if num == 1 then	
	script.Parent.Parent.Torso.CFrame = game.Workspace.planetbeam.CFrame + Vector3.new(0,5,0)
	elseif num == 2 then	
	script.Parent.Parent.Torso.CFrame = game.Workspace.bridgebeam.CFrame + Vector3.new(0,5,0)
	elseif num == 3 then	
	script.Parent.Parent.Torso.CFrame = game.Workspace.brigbeam.CFrame + Vector3.new(0,5,0)
	elseif num == 4 then	
	script.Parent.Parent.Torso.CFrame = game.Workspace.medbeam.CFrame + Vector3.new(0,5,0)
end	
	script.Parent.Handle.Sound:play()
	wait(2.04)
	script.Parent:Destroy()
end
end

script.Parent.Activated:connect(transport)

Can anybody help?

2 comments

0

I'm not sure what math.randomseed does, but it shouldn't be picking 3 every time. Try testing more and see if it still picks 3 every single time.

0

math.randomseed is like that, i'd use a table and check if it's on there...

1 answer

I see 2 errors in your script. First of all, CFrame + Vector3 doesn't work, so you'd have to do CFrame * CFrame, how would you do that? Here:

local CFrame1 = CFrame.new(0, 0, 0)
local CFrame2 = CFrame.new(0, 50, 25)
local CFrame3 = CFrame1 * CFrame2

So, to fix off your script, it would be:

function transport()
    math.randomseed(tick())
    local num = math.random(1,4)
    wait()
    if num == 1 then    
    script.Parent.Parent.Torso.CFrame = game.Workspace.planetbeam.CFrame * CFrame.new(Vector3.new(0,5,0))
    elseif num == 2 then    
    script.Parent.Parent.Torso.CFrame = game.Workspace.bridgebeam.CFrame * CFrame.new(Vector3.new(0,5,0))
    elseif num == 3 then    
    script.Parent.Parent.Torso.CFrame = game.Workspace.brigbeam.CFrame * CFrame.new( Vector3.new(0,5,0))
    elseif num == 4 then    
    script.Parent.Parent.Torso.CFrame = game.Workspace.medbeam.CFrame * CFrame.new(Vector3.new(0,5,0))
end 
    script.Parent.Handle.Sound:play()
    wait(2.04)
    script.Parent:Destroy()
end
end

script.Parent.Activated:connect(transport)

Hope this helped :)

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