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

How can i make it so after player presses H he will be teleported to cursor?

I already have the local script

Local script: /////////////////////////////////////////////////////

local Player = game:GetService("Players")

local rp = game:GetService("ReplicatedStorage")
local Teleport = rp.Stand1Remotes:WaitForChild("Teleport")


local UIS = game:GetService("UserInputService")

local debounce = false
local cooldown = 10

UIS.InputBegan:Connect(function(input,isTyping)
	if isTyping then
		return
		
elseif input.KeyCode == Enum.KeyCode.H and debounce == false then
	debounce = true
	
	Teleport:FireServer()
	

	
		end
end)

Teleport.OnClientEvent:Connect(function()

		wait(cooldown)
	debounce = false
end)

////////////////////////////////////////////

i can do anything in the script heres what i could do :3

local rp = game:GetService("ReplicatedStorage") local Teleport = rp.Stand1Remotes:WaitForChild("Teleport")

////////////////////////////////////////

4 comments

0

Try doing something with mouse.Hit

0
0

I will answer this in an hour ok?

0

take your time :)

2 answers

✓ Accepted answer

Okay so first of all, the Character belongs to the player so no need to handle it with a server script! Sometimes, the answer is just in our palms but we cannot reach to it...

--// Let's start with a simple userInputService system
local UIS = game:GetService('UserInputService')
local Player = game:GetService'Players'.LocalPlayer
local Mouse = Player:GetMouse() --// Gets the player's mouse
local Cooldown = false
UIS.InputBegan:Connect(function(key, IsTyping)
    if IsTyping or Cooldown then return end --// This will stop the player from teleporting while typing
    if key.KeyCode == Enum.KeyCode.H then --// Checks if the input is `H`
	Cooldown = true
        local Character = Player.Character or Player.CharacterAdded:Wait() --// Why define it under the event? Well, that is because when the player dies, character replaces unlike the player
        local Root = Character:WaitForChild('HumanoidRootPart')
        Root.CFrame = Mouse.Hit --// Mouse.Hit is a CFrame!
	wait(3)
	Cooldown = false
    end
end)

Hopefully this makes sense!

4 comments

0

is this just for local

0

bcs im gonna add effects to it so if its just for local it iwll only show for the local player

0

also is there a way to add range to this??

0

i just need an answer to range

local player = game.Players.LocalPlayer -- player
local mouse = player:GetMouse() -- gets the cursor

mouse.KeyDown:Connect(function(key) -- when a player presses a button it will use this as the function
    if key == 'h' then -- detects if the player presses 'h'
        player.Character.HumanoidRootPart.CFrame = mouse.Hit -- teleports the player to cursor
        end
end)

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