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

Player Steps on Part, Part Inserts GUI, GUI Button Teleports Player?

Hey, so I'm trying to figure out when I step on this brick, it gives me a GUI, and inside this GUI has a button that can teleport me to a certain place on the map. It doesn't seem to work, and I'm pretty frustrated lol, if anyone can help that would be awesome!

local plr = game.Players.LocalPlayer
local pos1 = game.pos1

function Click()
	script.Parent.Parent.Parent.Parent = pos1 --This is probably totally wrong but if they click on it, they get teleported lol.
end

if Click() then
	plr.ScreenGUI:remove() -- idk if this is right but if they click on it, it removes the GUI.
end

script.Parent.MouseButton1Down:connect(Click)

--BELOW IS WHEN THEY STEP ON THE PART THE GAME INSERTS THE GUI.


local debounce = false

function getPlayer(humanoid) 
local players = game.Players:children() 
for i = 1, #players do 
if players[i].Character.Humanoid == humanoid then return players[i] end 
end 
return nil 
end 

function onTouch(part) 

local human = part.Parent:findFirstChild("Humanoid") 
if (human ~= nil) and debounce == false then

debounce = true

local player = getPlayer(human) 

if (player == nil) then return end 

script.Parent:clone().Parent = player.PlayerGui

wait(2)
debounce = false
end
end


script.Parent.Parent.Touched:connect(onTouch) 

--This whole script is inserted into the ScreenGUI.

I'm not a great scripter but hopefully I can learn from all of you! (:

Thanks, LukeGabrieI

1 answer

✓ Accepted answer

There is no need for two scripts. Just put this in the part you want people to touch.

local part=game.Workspace.Part1 -- the part you want to teleport the player to teleport to
local d=true -- debounce
script.Parent.Touched:connect(function(limb)
	if game:GetService("Players"):FindFirstChild(limb.Parent.Name) then
		if d==true then
			d=false
			local plr=game:GetService("Players"):GetPlayerFromCharacter(limb.Parent)
			local gui=Instance.new("ScreenGui",plr.PlayerGui)
			local button=Instance.new("TextButton",gui)
			button.Size=UDim2.new(0,200,0,50)
			button.MouseButton1Down:connect(function()
				plr.Character.Torso.CFrame=part.CFrame+Vector3.new(0,2,0)
				gui:remove''
				d=true
			end)
		end
	else
		return
	end
end)

5 comments

0

How would I add text to the button through the script?

1

You would have to put another line after "local button=Instance.new..." that says "button.Text="TEXT""

0

How would I move the button to a certain place on the screen? lol, sorry for asking a lot!

0

nvm i got it

0

I'm okay with questions, no matter how many you ask.

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