local debounce = false
script.Parent.ActivatingRegion.Transparency = 0
local function UnleashThing(Part)
print("Touch")
print(Part.AssemblyLinearVelocity.Magnitude * script.Parent.ActivatingRegion.Size.Magnitude)
if game.Players:GetPlayerFromCharacter(Part.Parent) and Part.AssemblyLinearVelocity.Magnitude * script.Parent.ActivatingRegion.Size.Magnitude > 1500 then
if debounce == false then
debounce = true
workspace.Music.Scream:Play()
Part.Parent.MovementScript.SpeedVal.Value = 4
script.Parent.ActivatingRegion.Object.Value:Fire(game.Players:GetPlayerFromCharacter(Part.Parent))
wait(8)
debounce = false
end
end
end
local function RespawnDoor(Region)
repeat wait() until game.Players:FindFirstChildWhichIsA("Player")
game.Players:FindFirstChildWhichIsA("Player").CharacterAdded:Wait()
local c = Region:Clone()
c.Transparency = 0
c.Parent = script.Parent
c.Touched:Connect(UnleashThing)
c.AncestryChanged:Connect(RespawnDoor)
end
script.Parent.ActivatingRegion.Touched:Connect(UnleashThing)
script.Parent.ActivatingRegion.AncestryChanged:Connect(RespawnDoor)
The part gets destroyed after being touched (not on this script though), so i made it so when it’s Parent property was changed to nil, it would make a new part, and it does, the problem is that the connections don’t seem to work, as the function that would trigger when the part is touched doesn’t happen.
I think maybe it is because deleting the part removes it before the function can connect?
Maybe you should move it to server storage and replace it then delete it so the function has time to work?
local function RespawnDoor(child, parent)
repeat wait() until game.Players:FindFirstChildWhichIsA("Player")
game.Players:FindFirstChildWhichIsA("Player").CharacterAdded:Wait()
if not parent then
local c = child:Clone()
c.Transparency = 0
c.Parent = script.Parent
c.Touched:Connect(UnleashThing)
c.AncestryChanged:Connect(RespawnDoor)
end
end
script.Parent.ActivatingRegion.AncestryChanged:Connect(RespawnDoor)