Hi, there! I’m trying to make a building system in Roblox, but when I fire a remote event to the server the so called “mouse position” is not labeled as “Vector3”, but as “any”. Here’s my LocalScript:
local player = game.Players.LocalPlayer
local buildingMode = false
local cursorIndicator = nil
local function toggleBuildingMode()
buildingMode = not buildingMode
if buildingMode then
print("Building mode ON")
script.Parent.TextLabel.Text = "ON"
game.ReplicatedStorage.EnableBuild:FireServer(player)
else
print("Building mode OFF")
script.Parent.TextLabel.Text = "OFF"
game.ReplicatedStorage.DisableBuild:FireServer(player)
end
end
script.Parent.Activated:Connect(toggleBuildingMode)
game:GetService("UserInputService").InputBegan:Connect(function(input, isProcessed)
if not isProcessed and input.UserInputType == Enum.UserInputType.Keyboard then
if input.KeyCode == Enum.KeyCode.R then
toggleBuildingMode()
end
end
end)
-- Add this part to handle placing objects while in building mode
local function placeObject()
if buildingMode then
local inputService = game:GetService("UserInputService")
local position = nil
if inputService.TouchEnabled then
local touch = inputService.TouchStarted:wait()
if touch then
position = touch.Position
end
else
position = inputService:GetMouseLocation()
end
if position then
-- Call the server to place the object
game.ReplicatedStorage.BuildEvent:FireServer(player, position)
print("Success")
end
end
end
game:GetService("UserInputService").InputBegan:Connect(function(input, isProcessed)
if not isProcessed and (input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch) then
placeObject()
end
end)
You wouldn’t need to see the ServerScript, as I’ve made no progress on that one other than the connecting to the function.
Any help appreciated! Also please point out if the position of the mouse is wrong or it seems off compared to normal building systems. Thanks!