Hey guys,
In this script I am trying to spawn a House, or building onto my mouse position, using the :GetMouse() function. This is basically replicated tower defense or city maker games, just on a super basic level.
The issue im finding with this script is that the model spawns halfway through the baseplate, instead of its bottom being connected to the baseplate.
example of this: Gyazo link of problem
Is there any setting in the model that I could activate so that it cant go through, or is it something to do with scripting it in. any help is appreciated
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local SpawnFolder = ReplicatedStorage.Spawnables
local Switch = false
local debounce = false
local OnexButton = script.Parent.MiniHouse
local OnexTButton = script.Parent.LongHouse
local TwoxOButton = script.Parent.ScrapperHouse
--detection
OnexButton.MouseButton1Down:Connect(function()
if Switch == false then
Switch = true
print("Started placing 1x1")
UIS.InputBegan:Connect(function(key, processed)
if processed then
return
end
if key.UserInputType == Enum.UserInputType.MouseButton1 then -- Detects if mouse is clicked
if Switch == true then
if debounce == false then
debounce = true
local SpawnableHouse = ReplicatedStorage.Spawnables.MiniSquare:Clone()
SpawnableHouse.PrimaryPart.Position = game.Players.LocalPlayer:GetMouse().Hit.p
SpawnableHouse.Parent = workspace
print("Right mouse button clicked! (1x1)")
debounce = false
Switch = false
end
end
end
end)
end
end)
OnexTButton.MouseButton1Down:Connect(function()
if Switch == false then
Switch = true
print("Started placing 2x1")
UIS.InputBegan:Connect(function(key, processed)
if processed then
return
end
if key.UserInputType == Enum.UserInputType.MouseButton1 then -- Detects if mouse is clicked
if Switch == true then
if debounce == false then
debounce = true
local SpawnableHouse = ReplicatedStorage.Spawnables.MiniLong:Clone()
SpawnableHouse.PrimaryPart.Position = game.Players.LocalPlayer:GetMouse().Hit.p
SpawnableHouse.Parent = workspace
print("Right mouse button clicked! (2x1)")
debounce = false
Switch = false
end
end
end
end)
end
end)
TwoxOButton.MouseButton1Down:Connect(function()
if Switch == false then
Switch = true
print("Started placing 1x2")
UIS.InputBegan:Connect(function(key, processed)
if processed then
return
end
if key.UserInputType == Enum.UserInputType.MouseButton1 then -- Detects if mouse is clicked
if Switch == true then
if debounce == false then
debounce = true
local SpawnableHouse = ReplicatedStorage.Spawnables.MiniTall:Clone()
SpawnableHouse.PrimaryPart.Position = game.Players.LocalPlayer:GetMouse().Hit.p
SpawnableHouse.Parent = workspace
print("Right mouse button clicked! (1x2)")
debounce = false
Switch = false
end
end
end
end)
end
end)
any help is appreciated, thank you