Hi there, I’m new to scripting but currently I’m stuck because it’s not even outputting anything, so I was wondering if there’s something wrong or that I have forgotten to add to my script/a workspace object
What it should do is move a model named boat to any hitPart that has been clicked on using a raycast
local moveCooldown = 0 -- Cooldown between movements in seconds
local moveInterval = 5 -- How far it actually moves in studs
local function MoveBoat(direction)
local currentTime = tick()
if currentTime - moveCooldown >= moveInterval then
moveCooldown = currentTime
local Boat = script.Parent
local newPosition = Boat.PrimaryPart.Position + direction * moveInterval
if newPosition.X >= -50 and newPosition.X <= 50 and -- Checks whether the boat actually stays in the boundries
newPosition.Z >= -50 and newPosition.Z <= 50 then
Boat:SetPrimaryPartCframe(CFrame.new(newPosition))
end
end
end
game:GetService("UserInputService").InputBegan:Connect(function(input, gameProcessedEvent)
print("Input detected")
if not gameProcessedEvent and input.UserInputType == Enum.UserInputType.MouseButton1 then
print("Left mouse button clicked")
local mouse = game.Players.LocalPlayer:GetMouse()
local ray = game.Workspace.CurrentCamera:ScreenPointToRay(mouse.X, mouse.Y)
local hitPart, hitPosition = game.Workspace:FindPartOnRay(ray)
if hitPart then
print("Hit part found")
MoveBoat(hitPosition.p)
end
end
end)