I am trying to make a bridge system. The idea is you place down planks that allow you to cross a gap. Only issue is one long part will allow you to pass. My goal is to make a system that will make the bridge collapse if too much weight (such as a person) stands on top of the bridge. Adding more support will make it strong enough to hold you.
See video:
This is my current code for that plank system you saw. I plan on changing this to adapt to the new system of course:
local Player = game:GetService("Players").LocalPlayer
local Mouse = Player:GetMouse()
UserInputService = game:GetService("UserInputService")
local secondPoint = false
local function MakePlank(StartPos, EndPos, startPoint, endPoint)
local distance = math.sqrt((StartPos.X - EndPos.X)^2 + (StartPos.Y - EndPos.Y)^2 + (StartPos.Z - EndPos.Z)^2)
local center = distance/2
print(distance)
local plank = Instance.new("Part")
plank.Name = "Plank"
plank.Anchored = true
plank.Size = Vector3.new(1,0.1,distance)
plank.Position = Vector3.new((StartPos.X + EndPos.X)/2, (StartPos.Y + EndPos.Y)/2, (StartPos.Z + EndPos.Z)/2)
plank.CFrame = CFrame.new(plank.CFrame.Position, EndPos)
plank.Parent = workspace.PlankAspects.Planks
end
UserInputService.InputEnded:Connect(function(input) --MakePoints
if secondPoint == false then
if input.UserInputType == Enum.UserInputType.MouseButton1 then
secondPoint = true
StartPos = Mouse.Hit.Position
print(StartPos)
if workspace.PlankAspects.Points:FindFirstChild("EndPoint") then
workspace.PlankAspects.Points:FindFirstChild("EndPoint"):Destroy()
workspace.PlankAspects.Points:FindFirstChild("StartPoint"):Destroy()
end
--make Point
startPoint = Instance.new("Part")
startPoint.Size = Vector3.new(0.5, 0.5, 0.5)
startPoint.Position = StartPos
startPoint.Shape = Enum.PartType.Ball
startPoint.Color = Color3.new(0, 1, 0)
startPoint.Anchored = true
startPoint.Name = "StartPoint"
startPoint.Parent = workspace.PlankAspects.Points
end
else
if input.UserInputType == Enum.UserInputType.MouseButton1 then
secondPoint = false
EndPos = Mouse.Hit.Position
print(EndPos)
--make Point
endPoint = Instance.new("Part")
endPoint.Size = Vector3.new(0.5, 0.5, 0.5)
endPoint.Position = EndPos
endPoint.Shape = Enum.PartType.Ball
endPoint.Color = Color3.new(1, 0, 0)
endPoint.Anchored = true
endPoint.Name = "EndPoint"
endPoint.Parent = workspace.PlankAspects.Points
MakePlank(StartPos, EndPos, startPoint, endPoint)
end
end
end)
:]