Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
MpAlex 16
2 years ago

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:

01local player = game.Players.LocalPlayer
02local mouse = player:GetMouse()
03 
04local teleportPassID = 112767933
05 
06game:GetService('UserInputService').InputBegan:Connect(function(input)
07    if input.KeyCode == Enum.KeyCode.T and game:GetService('MarketplaceService'):UserOwnsGamePassAsync(player.UserId, teleportPassID) or game:GetService('MarketplaceService'):UserOwnsGamePassAsync(player.UserId, 112617906) then
08        print("T")
09        local target = mouse.Hit
10        if target then
11            player.Character.HumanoidRootPart.CFrame = target + Vector3.new(0, 5, 0)
12        end
13    end
14end)

1 answer

Log in to vote
0
Answered by 2 years ago
Edited 2 years ago

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.

01local player = game.Players.LocalPlayer
02local mouse = player:GetMouse()
03 
04local teleportPassID = 112767933
05 
06game:GetService('UserInputService').InputBegan:Connect(function(input, gameProcessed)
07    if gameProcessed then return end
08 
09    if input.KeyCode == Enum.KeyCode.T and game:GetService('MarketplaceService'):UserOwnsGamePassAsync(player.UserId, teleportPassID) or game:GetService('MarketplaceService'):UserOwnsGamePassAsync(player.UserId, 112617906) then
10        print("T")
11        local target = mouse.Hit
12        if target then
13            player.Character.HumanoidRootPart.CFrame = target + Vector3.new(0, 5, 0)
14        end
15    end
16end)
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 MpAlex 16 — 2y
0
Oh my bad. Did not mean to add 'not'.. xInfinityBear 1777 — 2y
Ad

Answer this question