I'm trying to make it so where the player clicks relative to the game, it creates a new part at the position of their mouse.
It's incredibly easy to make this with :GetMouse() but on the wiki it recommends to use UserInputService instead for mouse stuff, but I don't know how to get it to work, it creates the parts way above where I clicked it and it isn't positioning to where I click. Why isn't this working?
local UserInputService = game:GetService('UserInputService') UserInputService.InputBegan:Connect(function(input, processed) if input.UserInputType == Enum.UserInputType.MouseButton1 then local p = Instance.new('Part') p.Parent = workspace p.Position = input.Position p.Anchored = true end end) UserInputService.InputChanged:Connect(function(input, processed) if input.UserInputType == Enum.UserInputType.MouseMovement then print('hi') end end)
Hi Yaba,
local uis = game:GetService("UserInputService"); local players = game:GetService("Players"); local player = players.LocalPlayer; local mouse = player:GetMouse(); uis.InputBegan:Connect(function(input, gp) if input.UserInputType == Enum.UserInputType.MouseButton1 then local p = Instance.new('Part') p.Parent = workspace p.Position = mouse.hit.p; p.Anchored = true end end)
Thanks,
Best regards,
~~ KingLoneCat