Hey,
i tried making a script that places a block, without raycast it just places it behind the camera so i tried raycasting, it doenst work, my error always says “ViewportSize” isnt a valid member of inputObject. What is wrong here?
local block = Instance.new("Part")
block.Name = "Block"
block.Anchored = true
block.FormFactor = "Custom"
block.Size = Vector3.new(2,2,2)
block.TopSurface = "Smooth"
block.BottomSurface = "Smooth"
block.Material = "Wood"
game:GetService("UserInputService").InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
local newBlock = block:Clone()
newBlock.Parent = game.Workspace
local ray = game.Workspace.CurrentCamera:ViewportPointToRay(input.ViewportSize.X / 2, input.ViewportSize.Y / 2)
local hitPart, hitPoint = game.Workspace:Raycast(ray.Origin, ray.Direction * 100)
if hitPart then
newBlock.CFrame = CFrame.new(hitPoint)
end
end
end)
Thanks for the help, i appreciate it!