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

How to make a 2X chance to teleport a specific player?

Hello. I have another scripting question. So, I have gotten help and managed to make a random player picker, and make that random player chosen teleport on the stage and do whatever for 100 seconds, then teleport back to spawn. However, I want to make a 2X chance to go on stage if that player pays 1000 points. So basically, I made a frame inside of starter GUI, which contains a text button that says, " 2X CHANCE TO GO ON STAGE" and when you press it, it checks if you have 1000 points, and if you do, it takes them away, just like if you payed for it, then I want to make the 2X chance basically give that specific player who payed the 1000 points have a double chance to go on stage. I ALSO HAVE A LEADERSTAT SET UP ALREADY.

Here is the script to get on stage, and after 100 seconds, you get teleported back to spawn:

repeat
	task.wait(12) -- `task.wait` is the "updated" version of `wait` and is more precise
	local num = math.random(1, #game.Players:GetChildren())
	local player = game.Players:GetChildren()[num]
	 
	local hrp = player.Character.HumanoidRootPart
	hrp.CFrame = CFrame.new(Vector3.new(11.667, 26.652, 95.261)) -- Teleport to where you wanted
	task.wait(100) -- Wait 100 Seconds
	    hrp.CFrame = CFrame.new(Vector3.new(-44.595, 23.642, 93.177)) -- Teleport back to spawn
	    until false

If you do not understand or have a question about this, please ask so.

Thanks, from Cubispaghettis.

1 answer

✓ Accepted answer

Your idea to get a random player from a table of players is a good start.

I think you should take this table of players and add the players with a 2X chance into the table a second time. That way they technically have a 2X chance because their name appears in the table twice instead of once.

local PlayerTable = game.Players:GetPlayers()

for i,v in pairs(game.Players:GetPlayers()) do
	if v.Has2XChance then --check if the player has a 2X chance, this is just an example
		table.insert(PlayerTable, v)
	end
end

local num = math.random(1, #PlayerTable)
local player = PlayerTable[num]

8 comments

0

Ok so when a player would click a text button, they are supposed to get a 2x chance to teleport. So, would I attach this script to that textbutton when clicked or where?

0

You would attach this script to wherever it chooses the player that goes up to the stage

0

Ok! Local or regular? I made it regular if i have to change it tell me if so. Can a local script have the words "local" in them?

0

And also I want it to be a GUI that when pressed, would fire this. Do you know how/what to change?

0

or is it already connected?

0

All scripts can have "local" them them. I would recommend putting this in a normal script.

0

ok

0

so by pressing a text button is it supposed to launch this? i think i might need to put something in a text button

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