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

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

Asked by 4 years ago

I already have the local script

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

01local Player = game:GetService("Players")
02 
03local rp = game:GetService("ReplicatedStorage")
04local Teleport = rp.Stand1Remotes:WaitForChild("Teleport")
05 
06 
07local UIS = game:GetService("UserInputService")
08 
09local debounce = false
10local cooldown = 10
11 
12UIS.InputBegan:Connect(function(input,isTyping)
13    if isTyping then
14        return
15 
View all 30 lines...

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

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

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

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

0
Try doing something with mouse.Hit rabbi99 714 — 4y
0
https://developer.roblox.com/en-us/api-reference/property/Mouse/Hit This link tells you all you need to know sheepposu 561 — 4y
0
I will answer this in an hour ok? Gingerely 245 — 4y
0
take your time :) themaxogamer 58 — 4y

2 answers

Log in to vote
1
Answered by
Gingerely 245 Moderation Voter
4 years ago
Edited 4 years ago

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...

01--// Let's start with a simple userInputService system
02local UIS = game:GetService('UserInputService')
03local Player = game:GetService'Players'.LocalPlayer
04local Mouse = Player:GetMouse() --// Gets the player's mouse
05local Cooldown = false
06UIS.InputBegan:Connect(function(key, IsTyping)
07    if IsTyping or Cooldown then return end --// This will stop the player from teleporting while typing
08    if key.KeyCode == Enum.KeyCode.H then --// Checks if the input is `H`
09    Cooldown = true
10        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
11        local Root = Character:WaitForChild('HumanoidRootPart')
12        Root.CFrame = Mouse.Hit --// Mouse.Hit is a CFrame!
13    wait(3)
14    Cooldown = false
15    end
16end)

Hopefully this makes sense!

0
is this just for local themaxogamer 58 — 4y
0
bcs im gonna add effects to it so if its just for local it iwll only show for the local player themaxogamer 58 — 4y
0
also is there a way to add range to this?? themaxogamer 58 — 4y
0
i just need an answer to range themaxogamer 58 — 4y
Ad
Log in to vote
-1
Answered by
danglt 185
4 years ago
1local player = game.Players.LocalPlayer -- player
2local mouse = player:GetMouse() -- gets the cursor
3 
4mouse.KeyDown:Connect(function(key) -- when a player presses a button it will use this as the function
5    if key == 'h' then -- detects if the player presses 'h'
6        player.Character.HumanoidRootPart.CFrame = mouse.Hit -- teleports the player to cursor
7        end
8end)

Answer this question