Hi! So I have this issue in my script, that should make the parts in a building rotate around randomly on different axis. But it keeps printing out “AngularVelocity is not a valid member of game.Workspace.ShownMaps.Cozy House.Wall”.
The “Wall” object is a normal part, so it’s probably because it picks that one first for some reason.
ServerScript:
--IF YOU DON'T WANNA CHANGE ON THE SCRIPT, PUT IT INSIDE THE MODEL--
local amount = 1568 --CHANGE NUMBER TO HOW MANY WELDS YOU HAVE (IT WILL PRINT OUT WHEN RUNNING THE GAME)
--EQATION FOR HOW MANY WELDS YOU WANT LEFT TO MAKE THE BUILDING COLLAPSE
local addition = amount / 3
local equation = amount / 2 + addition
--print(equation)
local timerMax = amount / 1.21
local timer = 0
local build = script.Parent
local selection = game.ReplicatedStorage.SelectedDisasters:GetChildren()
local Debounce = false
local Debounce2 = false
local Debounce3 = false
-- Function to connect to the "Earthquake" event
local function Shake()
if not Debounce3 then
Debounce3 = true
for _, part in ipairs(build:GetChildren()) do
if part and (part:IsA("Part") or part:IsA("UnionOperation") or part:IsA("MeshPart") or part:IsA("BasePart")) then
local minAngle = -30
local maxAngle = 30
local randomAngle = math.random(minAngle, maxAngle)
local radians = math.rad(randomAngle) -- Calculate radians from degrees
local speed = 10
local xVelocity = speed * math.cos(radians)
local zVelocity = speed * math.sin(radians)
local newVelocity = Vector3.new(xVelocity, 0, zVelocity)
part.AngularVelocity = newVelocity
end
end
end
wait(0.2)
end
local function Rumble()
if not Debounce2 then
Debounce2 = true
local minAngle = -360
local maxAngle = 360
local randomAngle = math.random(minAngle, maxAngle)
local radians = randomAngle * (math.pi / 180)
local speed = 10
local xVelocity = speed * math.cos(radians)
local zVelocity = speed * math.sin(radians)
for _,part in ipairs(build:GetChildren()) do
if part then
if part:IsA("Part") or part:IsA("UnionOperation") or part:IsA("MeshPart") or part:IsA("BasePart") then
local newVelocity = Vector3.new(xVelocity,0,zVelocity)
part.Velocity = newVelocity
wait(0.05)
end
end
end
wait(2)
Debounce2 = false
end
end
local function startRumble()
game["Run Service"].Heartbeat:Connect(Rumble)
game["Run Service"].Heartbeat:Connect(Shake)
end
local function collapse()
startRumble()
for _,v in ipairs(build:GetDescendants()) do
if v then
if v:IsA("Weld") or v:IsA("WeldConstraint") then
v:Destroy()
wait(math.random(0.1,0.15))
end
end
end
end
local function ConnectToEarthquake()
local earthquakeEvent = game.ReplicatedStorage.SelectedDisasters:FindFirstChild("Earthquake")
if earthquakeEvent and earthquakeEvent:IsA("RemoteEvent") then
if script.Parent.Parent == game.Workspace.ShownMaps then
if not Debounce then
game.ReplicatedStorage.SelectedDisasters.Earthquake.OnServerEvent:Connect(function()
Debounce = true
collapse()
wait(70)
Debounce = false
end)
end
end
end
end
-- Connect to the "Earthquake" event outside the Heartbeat event
game["Run Service"].Heartbeat:Connect(function(deltaTime)
ConnectToEarthquake()
-- You can perform other logic here related to the Heartbeat event if needed
end)
Any help appreciated!!! ![]()