A bug is occurring with me, with a pressure plate system that I am making. Basically, sometimes when I place the box, or when I move between it, it causes a bug (apparently the collision), and causes the entire script to break. I even tried to put a collision group to make it impossible for the box to move, but that didn’t solve it.
Here’s the Pressure Plate Script:
Pressure Plate Script
local PressurePlate = script.Parent
local hitBox = PressurePlate.Hitbox
local Center = PressurePlate.Center
local BoxsName = "Box20A"
local BoxInWorkspace
local BoxPrompt
local TWPart = workspace.StonePassage20A
local TweenService = game:GetService("TweenService")
local TInfo = TweenInfo.new(1.8, Enum.EasingStyle.Circular, Enum.EasingDirection.Out, 0, false, 0)
local Goal = {}
local CenterAnimation
local PassageAnimation
local BoxOnDebounce = false
--Make Passage
hitBox.Touched:Connect(function(hit)
if hit:IsA("Part") and hit.Name == BoxsName and (not BoxOnDebounce) then
BoxOnDebounce = true
BoxInWorkspace = workspace.Boxes[BoxsName]
BoxPrompt = BoxInWorkspace.Attachment.ProximityPrompt
BoxPrompt.Enabled = false
print("box is on")
--Turn Neon Thingy On
task.spawn(function()
local NeonPartOn = {
Color = Color3.fromRGB(255, 26, 26),
Sound = PressurePlate.NeonParts:WaitForChild("NeonOnSound")
}
if hit:IsA("Part") and hit.Name == BoxsName then
local newCFrame = Center.CFrame + Vector3.new(0, -0.25, 0)
CenterAnimation = TweenService:Create(Center, TInfo, {CFrame = newCFrame})
--CenterAnimation:Play()
task.spawn(function()
wait(6) -- Total Wait Time
BoxPrompt.Enabled = true
end)
for _, v in PressurePlate.NeonParts:GetChildren() do
if v:IsA("Part") then
v.Color = NeonPartOn.Color
NeonPartOn.Sound:Play()
wait(0.05)
end
end
end
end)
--Make Passage
for _, v in pairs(TWPart:GetDescendants()) do
if v:IsA("Part") or v:IsA("UnionOperation") then
local MovingStoneSound = v.MovingStoneSound
MovingStoneSound:Play()
Goal = {Position = v.Position + Vector3.new(0, 13, 0)}
PassageAnimation = TweenService:Create(v, TInfo, Goal)
PassageAnimation:Play()
wait(1)
end
end
end
end)
hitBox.TouchEnded:Connect(function(hit)
if hit:IsA("Part") and hit.Name == BoxsName and BoxOnDebounce then
BoxOnDebounce = false
BoxPrompt.Enabled = false
task.spawn(function()
local NeonPartOff = {
Color = Color3.fromRGB(8, 8, 8),
Sound = PressurePlate.NeonParts:WaitForChild("NeonOnSound")
}
if hit:IsA("Part") and hit.Name == BoxsName then
local newCFrame = Center.CFrame + Vector3.new(0, 0.25, 0)
-- TweenService:Create(Center, TInfo, {CFrame = newCFrame}):Play()
task.spawn(function()
wait(6) -- Total Wait Time
BoxPrompt.Enabled = true
end)
for _, v in PressurePlate.NeonParts:GetChildren() do
if v:IsA("Part") then
v.Color = NeonPartOff.Color
NeonPartOff.Sound:Play()
wait(0.05)
end
end
--Leave Passage
for _, v in pairs(TWPart:GetDescendants()) do
if v:IsA("Part") or v:IsA("UnionOperation") then
local MovingStoneSound = v.MovingStoneSound
MovingStoneSound:Play()
Goal = {CFrame = v.CFrame + Vector3.new(0, -13, 0)}
TweenService:Create(v, TInfo, Goal):Play()
wait(1)
end
end
end
end)
end
end)
And the Box Script:
Box Script
local grabbed = false
local BoxAlreadyExists = true
local Prompt = script.Parent.Attachment.ProximityPrompt
local ServerStorage = game:GetService("ServerStorage")
local BoxesFolder = workspace:WaitForChild("Boxes")
local Box = script.Parent
local BoxClone = Box:Clone()
local weld
Prompt.Triggered:Connect(function(player)
local Human = player.Character.HumanoidRootPart
local x = Human.CFrame.X
local y = Human.CFrame.Y - 1
local z = Human.CFrame.Z
if grabbed then
Human.Weld:Destroy()
Box.CanCollide = true
Box.CFrame = CFrame.new(x, y, z)
Box.CFrame = Box.CFrame + Human.CFrame.LookVector * 4
Box.Orientation = Human.Orientation
Box.Parent = BoxesFolder
Box.Massless = false
Box.CanTouch = true
grabbed = false
Prompt.ActionText = "Pick up"
wait(0.5)
elseif not grabbed then
Box.Parent = workspace:WaitForChild("Boxes")
Box.CFrame = CFrame.new(x, y, z)
Box.CFrame = Box.CFrame + Human.CFrame.LookVector * 4
Box.Orientation = Human.Orientation
Box.CanCollide = false
Box.Massless = true
Box.CanTouch = false
weld = Instance.new("WeldConstraint", Human)
weld.Part0 = Human
weld.Part1 = Box
weld.Name = "Weld"
grabbed = true
Prompt.ActionText = "Drop"
wait(0.5)
end
end)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage.PlayerDiedWithBox.PlayerDiedWithBoxRemote
RemoteEvent.OnServerEvent:Connect(function(player)
if grabbed then
Prompt.MaxActivationDistance = 0
Box.CanCollide = true
Box.Massless = false
Prompt.ActionText = "Pick up"
grabbed = false
wait(3)
Prompt.MaxActivationDistance = 10
end
end)
If possible, be able to find a way around the problem, or do something different. Because I don’t know what else to do