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

My OnClick teleporter (Still) Doesnt work?

I tinkered around with he script but everything still doesn't work

Here's the code

local CD = script.Parent
local block = script.Parent.Parent
	 
local function OnClicked()	   
	local Teleport = "Lentilkac58-Easy-Teleport-2" 
	
	local function Touch(hit)
	 	if script.Parent.Locked == false and script.Parent.Parent:FindFirstChild(Teleport).Locked == false then 
			script.Parent.Locked = true 				
			script.Parent.Parent:FindFirstChild(Teleport).Locked = true --Checks Debounce.
			
			local Pos = script.Parent.Parent:findFirstChild(Teleport) 
	
			hit.Parent:MoveTo(Pos.Position) 
			
			wait(1) 
			
			script.Parent.Locked = false 
			script.Parent.Parent:FindFirstChild(Teleport).Locked = false 
		end 
	end

	script.Parent.Touched:connect(Touch)
end
	 
CD.MouseClick:Connect(OnClicked)

here's the line it says is wrong:

(It wont work ON CLICK)

script.Parent.Touched:connect(Touch)

1 comment

0

youre creating a new touch event everytime you call the click event which means every time you click on the click detector, it creates a new touch event along with the other ones you created when you clicked the click detector before. i'd break up ur code and see if the click function works by printing out something.

1 answer

Here's the brand new code scripted just for you mate with some explanations.


-- Put the part to which you want to teleport to into the workspace.
-- Put this inside the normal script where your teleporter is located at.

local PARTNAME = "Teleporter2" -- Put the part name

-- Code

local buttonPressed = false

local ExitPart;

pcall(function()
ExitPart = workspace:WaitForChild(PARTNAME) -- Searches for the ExitPart in the Workspace where you should have put your teleport to part.
end)


script.Parent.ClickDetector.MouseClick:Connect(function(player)
	if not buttonPressed then -- Prevent's a tons of hits at once (thing called debounce)
		buttonPressed = true
			local Character =	player.Character
			Character:SetPrimaryPartCFrame(ExitPart.CFrame)
			Character.PrimaryPart.Position = Vector3.new(Character.PrimaryPart.Position.X, Character.PrimaryPart.Position.Y + 10, Character.PrimaryPart.Position.Z)
		buttonPressed = false
	end
end)


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