i have been making a building system for a game im developing. but i have run into an issue where the if statement doesnt work properly
if you want the full code here it is:
local mouse = game.Players.LocalPlayer:GetMouse()
local player = game.Players.LocalPlayer
local tp = script.TP
local build = require(game.ReplicatedStorage:WaitForChild("Build"))
local placing = false
local mousemoved = false
local place = false
local pos = nil
local placeable = true
mouse.Move:Connect(function()
mousemoved = true
end)
local function GetTouchingParts(part)
local connection = part.Touched:Connect(function() end)
local results = part:GetTouchingParts()
connection:Disconnect()
return results
end
mouse.Button1Down:Connect(function()
if placing == true and placeable == true then
place = true
wait(0.1)
build.Build(script.Parent.Parent.BUILDING.Value,pos)
wait(0.1)
pos = nil
placing = false
place = false
end
end)
script.Parent.MouseButton1Click:Connect(function()
if placing == false then
wait(0.1)
placing = true
local building = script.Parent.Parent.BUILDING.Value:Clone()
building.Parent = workspace
print(building.Body.Hitbox:GetTouchingParts())
local buildingtp = tp:Clone()
buildingtp.Parent = workspace
while true do
if mousemoved == true then
if placeable == true then
buildingtp.Position = mouse.hit.Position
building.Body:SetPrimaryPartCFrame(CFrame.new(buildingtp.CFrame.X,building.TRAITS.OFFSET.Value.Y,buildingtp.CFrame.Z),buildingtp)
mousemoved = false
end
end
if place == true then
place = false
pos = building.Body:GetPrimaryPartCFrame()
building:Remove()
buildingtp:Remove()
break
end
print(GetTouchingParts(building.Body.Hitbox))
for i,v in pairs(GetTouchingParts(building.Body.Hitbox)) do
print(v.Name)
if v.Name == "Hitbox" then --Problem Here
--it will never ever go here
building.Body.Hitbox.Transparency = 0.5
building.Body.Hitbox.BrickColor = BrickColor.new("Really red")
placeable = false
print("true")
else
--no matter what it goes here:
building.Body.Hitbox.Transparency = 1
placeable = true
print("false")
end
end
wait()
end
end
end)
so i really hope someone will help with this
thanks :)
