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

I made a teleport script and the player is teleporting while I type in chat, how can i fix this?

I'm trying to make a gamepass that allows the player to teleport anywhere he is pointing with the mouse cursor but the problem is that i can teleport while i'm typing.

As example if i want to say in chat "Today is Thursday" the player will teleport 2 times.

Here is the code:

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

local teleportPassID = 112767933

game:GetService('UserInputService').InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.T and game:GetService('MarketplaceService'):UserOwnsGamePassAsync(player.UserId, teleportPassID) or game:GetService('MarketplaceService'):UserOwnsGamePassAsync(player.UserId, 112617906) then
		print("T")
		local target = mouse.Hit
		if target then
			player.Character.HumanoidRootPart.CFrame = target + Vector3.new(0, 5, 0)
		end
	end
end)

1 answer

✓ Accepted answer

You can use the parameter that comes with this event called GameProcessedEvent.

Indicates whether the game engine internally observed this input and acted on it. Generally this refers to UI processing, so if a button was touched or clicked from this input, gameProcessedEvent would be true. This is also true for input events connected via ContextActionService.

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

local teleportPassID = 112767933

game:GetService('UserInputService').InputBegan:Connect(function(input, gameProcessed)
	if gameProcessed then return end

	if input.KeyCode == Enum.KeyCode.T and game:GetService('MarketplaceService'):UserOwnsGamePassAsync(player.UserId, teleportPassID) or game:GetService('MarketplaceService'):UserOwnsGamePassAsync(player.UserId, 112617906) then
		print("T")
		local target = mouse.Hit
		if target then
			player.Character.HumanoidRootPart.CFrame = target + Vector3.new(0, 5, 0)
		end
	end
end)

2 comments

0

thank you for your help, it worked when i removed "not" from the line you added, it looks like this: if gameProcessed then return end

0

Oh my bad. Did not mean to add 'not'..

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