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

How do I change Keyclick To mouse click?

Asked by
2mania 14
1 year ago

Thx to T3_MasterGamer for the script if u see this can u help me again lol

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local UserInputService = game:GetService("UserInputService")

UserInputService.InputBegan:Connect(function(input)
    if input.UserInputType == script.Parent.MouseButton1Click then
        local part2 = Instance.new("Part", workspace)
        part2.CanCollide = false
        part2.Anchored = true
        part2:PivotTo(character:WaitForChild("Head"):GetPivot() * CFrame.new(0, 0, 5))
        part2.Name = "Part1"

        character:WaitForChild("Humanoid"):MoveTo(part2.Position, part2)
    end
end)

1 answer

Log in to vote
0
Answered by 1 year ago
Edited 1 year ago

What you're doing is wrong. You're trying to check if the input's UserInputType which is an event, not an enum. You don't need to use UserInputService.InputBegan if you will change it to a mouse click. Replace that event with script.Parent.MouseButton1Click event.

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()

script.Parent.MouseButton1Click:Connect(function()
    local part2 = Instance.new("Part", workspace)
    part2.CanCollide = false
    part2.Anchored = true
    part2:PivotTo(character:WaitForChild("Head"):GetPivot() * CFrame.new(0, 0, 5))
    part2.Name = "Part1"

    character:WaitForChild("Humanoid"):MoveTo(part2.Position, part2)
end)

But if you want both for "E" and button (i assume for pc and mobile) you can create one function and connect that function to the two events (UserInputService.InputBegan and GuiButton.MouseButton1Click) altogether in one script (make sure that script is inside the button).

local player = game:GetService("Players").LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local UserInputService = game:GetService("UserInputService")

function MovePlayer()
    local part2 = Instance.new("Part", workspace)
    part2.CanCollide = false
    part2.Anchored = true
    part2:PivotTo(character:WaitForChild("Head"):GetPivot() * CFrame.new(0, 0, 5))
    part2.Name = "Part1"

    character:WaitForChild("Humanoid"):MoveTo(part2.Position, part2)
end

UserInputService.InputBegan:Connect(function(input)
    if input.KeyCode == Enum.KeyCode.E then
        MovePlayer()
    end
end)
script.Parent.MouseButton1Click:Connect(function()
    MovePlayer()
end)
0
I tried that earlier and it didnt work LOL 2mania 14 — 1y
0
wdym?? T3_MasterGamer 2189 — 1y
0
sure i'll edit it in a bit T3_MasterGamer 2189 — 1y
0
there i edited it, should work now T3_MasterGamer 2189 — 1y
Ad

Answer this question