so right now i have a script (below) which is a placement script. there is a part below which is supposed to see if a block is being touched then turn it red but it isnt working too well. (vid below) https://streamable.com/fx84wh
wait()
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local mouse = player:GetMouse()
local plan = game.ReplicatedStorage.Wall.Selection
local build = game.ReplicatedStorage.Wall.Place
local pos = Vector3.new(0,0,0)
local a = 0
local canplace = true
script.Parent.Equipped:Connect(function(mouse)
local plan1 = plan:Clone()
plan1.Parent = game.Workspace
mouse.TargetFilter = workspace.Selection
mouse.Button1Down:connect(function()
if canplace == true then
local build1 = build:Clone()
build1.Parent = game.Workspace
build1.Position = plan1.Position
mouse.TargetFilter = workspace.Selection
end
end)
local Model = game.Workspace.Selection
while wait() do
game.Workspace.Selection.Touched:Connect(function(Touch)
if Touch:IsA("Part") then
Model.Color = Color3.fromRGB(255, 0, 0)
canplace = false
end
end)
game.Workspace.Selection.TouchEnded:Connect(function()
Model.Color = Color3.fromRGB(0, 255, 0)
canplace = true
end)
pos = Vector3.new(math.floor(mouse.Hit.p.X),math.floor(mouse.Hit.p.Y),math.floor(mouse.Hit.p.Z))
plan1.Position = pos+Vector3.new(0,6,0)
end
end)
script.Parent.Unequipped:Connect(function()
workspace.Selection:Destroy()
end)
heres the part that supposed to detect the touch
game.Workspace.Selection.Touched:Connect(function(Touch)
if Touch:IsA("Part") then
Model.Color = Color3.fromRGB(255, 0, 0)
canplace = false
end
end)
game.Workspace.Selection.TouchEnded:Connect(function()
Model.Color = Color3.fromRGB(0, 255, 0)
canplace = true
end)
please help me fix this
