Issue : Mouse.Hit isnt hitting the ground
WantTo : I want to make mouse.Hit hit the ground like when the mouse moves, It will hit the ground instead of air
Scripts
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Structures = workspace.Structures
local Shapes = ReplicatedStorage.Shapes
local Maps = workspace.Maps
local Gui = script.Parent
local bg = Gui.bg
local Selector = bg.Selector
local Title = bg.Title
local player = Players.LocalPlayer
local Character = player.Character or player.CharacterAdded:Wait()
local Mouse = player:GetMouse()
local function Set(shape :string, amount :number)
Selector[shape].Amount.Text = amount
end
local function Add(shape :string, amount :number)
Selector[shape].Amount.Text = tonumber(Selector[shape].Amount) + amount
end
local function Remove(shape :string, amount :number)
Selector[shape].Amount.Text = tonumber(Selector[shape].Amount) - amount
end
local ObstacleFunctions = {
Killbrick = function(part)
part.Touched:Connect(function(hit)
if hit.Parent == Structures then
hit:Destroy()
elseif Players:GetPlayerFromCharacter(hit.Parent) then
pcall(function()
hit.Parent.Humanoid.Health = 0
end)
end
end)
end,
PlayerKillbrick = function(part)
part.Touched:Connect(function(hit)
if Players:GetPlayerFromCharacter(hit.Parent) then
pcall(function()
hit.Parent.Humanoid.Health = 0
end)
end
end)
end,
StructureKillbrick = function(part)
part.Touched:Connect(function(hit)
if hit.Parent == Structures then
hit:Destroy()
end
end)
end,
StructureRespawner = function(part)
print(part)
part.Touched:Connect(function(hit)
print(hit)
if Players:GetPlayerFromCharacter(hit.Parent) then
local s, r = pcall(function()
for _, config in pairs(part:GetChildren()) do
if not config:IsA("NumberValue") then
print(config)
continue
end
print(config)
Set(config.Name, config.Value)
end
end)
assert(s, r)
end
end)
end,
StructurePassable = function(part)
end,
StructurePoison = function(part)
end,
PlayerPoison = function(part)
end,
PlayerPassable = function(part)
end,
Unplaceable = function(part)
end,
Poison = function(part)
end,
Teleporter = function(part)
end,
}
local OtherFunctions = {
PlaceBlock = function()
for _, button in pairs(Selector:GetChildren()) do
if not button:IsA("TextButton") then
continue
end
local mode = nil
button.MouseButton1Click:Connect(function()
if mode ~= nil then
mode = nil
return
end
pcall(function()
mode = false
local structure = Shapes[button.Name]:Clone()
structure.Transparency = 0.5
structure.Parent = Structures
local strColor = structure.Color
structure.Color = Color3.fromRGB(0, 255, 0)
task.spawn(function()
Mouse.Button1Down:Wait()
mode = true
end)
repeat
local X, Y, Z = Mouse.Hit.X, Mouse.Hit.Y, Mouse.Hit.Z
structure.Position = Vector3.new(math.round(X), math.round(Y), math.round(Z))
task.wait()
until mode or mode == nil
structure.Transparency = 0
structure.Color = strColor
structure.CanCollide = true
end)
end)
end
end,
}
for _, Function in pairs(OtherFunctions) do
Function()
end
for _, map in pairs(Maps:GetChildren()) do
for obsName, obsSystem in pairs(ObstacleFunctions) do
local obsFolder = map:FindFirstChild(obsName)
if not obsFolder then
continue
end
for _, obsPart in pairs(obsFolder:GetChildren()) do
pcall(function()
obsSystem(obsPart)
end)
end
end
end
robloxapp-20240908-0848084.wmv (973.7 KB)
And yes I watch every topic, But I don’t find one
Anyways, Thanks for reading!
Edit : If you don’t wanna read entire script
Its this issue
repeat
local X, Y, Z = Mouse.Hit.X, Mouse.Hit.Y, Mouse.Hit.Z
structure.Position = Vector3.new(math.round(X), math.round(Y), math.round(Z))
task.wait()
until mode or mode == nil
Edit 2 : Structure is a block in the video, Mouse is player:GetMouse()
mode is:
When the block is placed, mode is true (Didnt do that yet)
When the block is selected, mode is false
When the block is not selected, mode is nil (Didnt do properly either)