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

I need my script to choose one position in 3 random and get a pad to teleport to a part constantly?

I'm trying to add an extra position for my give to teleport and a pad to teleport with it. Here's my script: This is the Give script, the give part is invisible:

local randomValue
local position1 = Vector3.new(-66.32, 5.572, -92.15)--(-66.91 -100.99)
local position2 = Vector3.new(-66.32, 5.572, -106.94)--(-66.91 -100.99)

script.Parent.Touched:Connect(function(Hit)
	
	randomValue = math.random(1,2)
	local player = game.Players:GetPlayerFromCharacter(Hit.Parent.Parent)
	print(Hit.Parent.Name)
	local char = Hit.Parent
	if Hit.Name == 'JobBox' then
		print('BOXHIT')
		script.Parent.Parent.Anim.Value = 'false'
		script.Parent.Parent.Taken.Value = 'false'
		player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + 2
		Hit:Destroy()
		script.Parent.Parent.AnimScript.Disabled = true
		script.Parent.Parent.AnimScript.Disabled = false
		
		if randomValue == 1 then
			
			script.Parent.Position = position1
			
		else
			
			script.Parent.Position = position2--I want to add an extra value
			
		end
	end
end)

Here's the pad script. The pad isn't invisible so you can see the pad:

while true do
	script.Parent.Position = script.Parent.Parent.Give.Vector3(0, -3, 0)
	wait(0.001)
end

I want the pad to keep teleporting to the Give.

Thank you.

1 comment

0

I've edited my answer for that pad script

1 answer

✓ Accepted answer

I remember I answered your question about getting random vector3's. I said you could use elseif's, so let's get to work. Here is how you use them:

local value = 1

if value == 2 then
	
	print("2") -- it will not print because it is not 2, and will move into the next check
	
elseif value == 3 then
	
	print("3") -- it will not print because it is not 3, and will move into the next check
	
elseif value == 1 then
	
	print("1") -- this will print as it is 1
	
else -- you can also use an else wich will fire incase it is not 2, 3 or 1(you wont need it for this code)
	
	print("it's not 1, 3 and neither 2!")
	
end

Basically, if the first requirement is not met, it will move into the other elseif, and if the requirement is not met, it will go into the next, etc. So here is how we will implement that into your script:

local randomValue
local position1 = Vector3.new(-66.32, 5.572, -92.15)--(-66.91 -100.99)
local position2 = Vector3.new(-66.32, 5.572, -106.94)--(-66.91 -100.99)
local position3 = Vector3.new(0, 1,0) -- i will put some random values here
local position4 = Vector3.new(0, 0,1)

script.Parent.Touched:Connect(function(Hit)

    randomValue = math.random(1,4) -- since we have four positions, we need it to get a random number between 1 and 4
    local player = game.Players:GetPlayerFromCharacter(Hit.Parent.Parent)
    print(Hit.Parent.Name)
    local char = Hit.Parent
    if Hit.Name == 'JobBox' then
        print('BOXHIT')
        script.Parent.Parent.Anim.Value = 'false'
        script.Parent.Parent.Taken.Value = 'false'
        player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + 2
        Hit:Destroy()
        script.Parent.Parent.AnimScript.Disabled = true
        script.Parent.Parent.AnimScript.Disabled = false

        if randomValue == 1 then

            script.Parent.Position = position1

        elseif randomValue == 2 then

            script.Parent.Position = position2

        elseif randomValue == 3 then

            script.Parent.Position = position3

        elseif randomValue == 4 then

            script.Parent.Position = position4

        end
    end
end)

Hope this helped you! Edit: to make that pad teleport correctly do this:

while true do
    script.Parent.Position = script.Parent.Parent.Give.Position -- just changed it to position
    wait(0.001)
end

2 comments

0

Thanks, this really helped me but I need my pad to teleport to it constantly have you got any suggestions on how to do it?

0

Oh, right nvm then. Thanks!

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