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

How can i make a text button can teleport a player to a random position when they clicked it ?

im creating my sword fighting game, im creating a textbutton that can teleport a player with a random x,y position when they clicked on it, someone help me

2 comments

0

sorry to say this, but this site isn’t about giving out free code, maybe search up a way to do what you want to do, or find a post on devforum and see if there’s solution there

0

oh, sorry about that but i actually made a code and i already have the idea, just something went wrong

1 answer

Hey, I'll give you the code but please read and understand what I am giving you. Just copying and pasting this code wont help you in your scripting career.

You firstly need to make a Part, (call it Part1 just for now), and where that part is desides on where the Player will teleport.

Then inside the TextButton add a local script, and now put this inside:

wait(1)
player = game.Players.LocalPlayer --Where the player is located
button = script.Parent --Where the button is locaed (script.Parent is the parent from the script)
local debounce = false --debounce is sort of a cool down, aka preventing things from firing.

function teleport() --function teleport means what will happen when the function teleport() is fired. 
	if not debounce then --If the debounce is false (if not)
		debounce = true --The script makes it true
		local LowerTorso = player.Character.LowerTorso --Now in here we say where the lower torso of the player is
		LowerTorso.CFrame = game.Workspace.Part1.CFrame --Now in here is where the CFrame of the Player's LowerTorso is. Where is says "Part1", put the name of the part that you will get teleported to.
		wait(0.1) --It will wait 0.1 seconds before the next event will happen.
		script.Parent.Parent.Visible = false --The button will become non visible, meaning that the player wont see the button again when they press the button. Remove this if you still want the button to be seen, but they will still be teleported at the same spot.
	end
end

button.MouseButton1Click:Connect(teleport)  --When the button is clicked
while true do wait() --While its true, wait
	debounce = false --The debounce becomes false
	wait(1) --Wait 1 second before its fired again
end

Thats the end, please reply if you have any other questions, or if somthing is unclear, or if it wont work, etc.

1 comment

0

ok thanks, you helped me a lot !

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