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: /////////////////////////////////////////////////////

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")

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

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

--// 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!

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

Answer this question