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

How do I change Keyclick To mouse click?

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

✓ Accepted answer

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)

4 comments

0

I tried that earlier and it didnt work LOL

0

wdym??

0

sure i'll edit it in a bit

0

there i edited it, should work now

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