Okay, so this script makes a brick get pushed when you touch it, towards the direction you pushed it in. The only problem is it only goes left and right for some reason; never back and forth.
canPush = true
script.Parent.Touched:connect(function(hit)
if canPush == true then canPush = false
local back = Vector3.new(script.Parent.CFrame.X + script.Parent.Size.X/2, script.Parent.Size.Y, script.Parent.Size.Z)
local front = Vector3.new(script.Parent.CFrame.X - script.Parent.Size.X/2, script.Parent.Size.Y, script.Parent.Size.Z)
local right = Vector3.new(script.Parent.Size.X, script.Parent.Size.Y, script.Parent.CFrame.Z - script.Parent.Size.X/2)
local left = Vector3.new(script.Parent.Size.X, script.Parent.Size.Y, script.Parent.CFrame.Z + script.Parent.Size.X/2)
local frontmag = (front - hit.Position).magnitude
local backmag = (back - hit.Position).magnitude
local leftmag = (left - hit.Position).magnitude
local rightmag = (right - hit.Position).magnitude
if frontmag < backmag and frontmag < rightmag and frontmag < leftmag then
for i = 1, 40 do
wait()
script.Parent.CFrame = script.Parent.CFrame - Vector3.new(-0.1, 0, 0)
end
elseif backmag < frontmag and backmag < rightmag and backmag < leftmag then
for i = 1, 40 do
wait()
script.Parent.CFrame = script.Parent.CFrame + Vector3.new(-0.1, 0, 0)
end
elseif rightmag < frontmag and rightmag < backmag and rightmag < leftmag then
for i = 1, 40 do
wait()
script.Parent.CFrame = script.Parent.CFrame - Vector3.new(0, 0, -0.1)
end
elseif leftmag < frontmag and leftmag < backmag and leftmag < rightmag then
for i = 1, 40 do
wait()
script.Parent.CFrame = script.Parent.CFrame + Vector3.new(0, 0, -0.1)
end
end
wait(1)
canPush = true
end
end)
...thats why yellow makes me sad |