So I have a very good working mechanic SCP-106 (Old Man). When you press the R button, a hole appears near you and near one player, through which you can pass and end up in another hole, I thought it would be more difficult to do, but still I have one problem left. When I start going through a hole during the removal of this hole, I am in place and the script that performs the animation and teleport is simply deleted along with the hole. And I can’t do anything and just get stuck, I would like to know how I can, when removing a hole, make the character stop playing animation and unanchor the primary part of the player
Script in hole:
script.Parent.ProximityPrompt.Triggered:Connect(function(plr)
script.Parent.ProximityPrompt.Enabled = false
if plr.Character:FindFirstChild("Zombie") and plr.Character:FindFirstChild("OldMan") then
local animplay = plr.Character.Zombie:LoadAnimation(script.Parent.Animation)
plr.Character.PrimaryPart.Anchored = true
animplay:Play()
script.Parent.Decay:Play()
wait(6)
for i,v in pairs(workspace:GetDescendants()) do
if v.Name == script.Parent.Value.Value then
plr.Character.PrimaryPart.Position = v.Position + Vector3.new(0,3,0)
script.Parent.Decay:Play()
v.ProximityPrompt.Enabled = false
wait(3)
v.ProximityPrompt.Enabled = true
elseif v == nil then
animplay:Stop()
plr.Character.PrimaryPart.Anchored = false
end
end
script.Parent.ProximityPrompt.Enabled = true
plr.Character.PrimaryPart.Anchored = false
end
end)
script in hole that makes you teleport in right way (just changes the value name in this hole):
while true do
if script.Parent.Name == "hole1" then
script.Parent.Value.Value = "hole2"
elseif script.Parent.Name == "hole2" then
script.Parent.Value.Value = "hole1"
end
task.wait()
end
Script that creates the hole means attack script in tool (not full):
function Create()
if dega then return end
dega = true
local hole1 = game.ReplicatedStorage.Holes.SCPHOLE:Clone()
hole1.Name = "hole1"
hole1.Parent = workspace
hole1.Position = script.Parent.Parent.PrimaryPart.Position - Vector3.new(0,3,0)
local hole2 = game.ReplicatedStorage.Holes.SCPHOLE:Clone()
hole2.Name = "hole2"
hole2.Position = Vector3.new(-31.559, 0.585, -70.882)
hole2.Parent = workspace
for i,v in pairs(game.Workspace:GetChildren()) do
if v:IsA("Model") then
if v:FindFirstChild("Humanoid") then
if not v:FindFirstChild("Targeted106") then
hole2.Position = v.PrimaryPart.Position - Vector3.new(0,3,0)
local targeted = Instance.new("BoolValue")
targeted.Parent = v
targeted.Name = "Targeted106"
game:GetService("Debris"):AddItem(hole2,27)
game:GetService("Debris"):AddItem(hole1,27)
game:GetService("Debris"):AddItem(targeted,34)
task.wait(27)
dega = false
break
end
end
end
end
end
script.Parent.CreateHole.OnServerEvent:Connect(Create)
One of the problems I can fix is moving the player as of now.
A more efficient way of moving the player is modifying the player humanoid’s CFrame instead of the position. If you don’t know what CFrame’s are, they’re just a short term for CoordinateFrames which helps move a part that is welded to another part, via the Weld, WeldConstraint or Motor6D instance.
The reason why we’ll move the PrimaryPart with CFrame’s is because it’s welded to the Torso of the player, while the torso is welded to the limbs by way of Motor6D.
So with that out of the way, now we can analyze your code.
script.Parent.ProximityPrompt.Triggered:Connect(function(plr)
script.Parent.ProximityPrompt.Enabled = false
if plr.Character:FindFirstChild("Zombie") and plr.Character:FindFirstChild("OldMan") then
local animplay = plr.Character.Zombie:LoadAnimation(script.Parent.Animation)
plr.Character.PrimaryPart.Anchored = true
animplay:Play()
script.Parent.Decay:Play()
wait(6)
for i,v in pairs(workspace:GetDescendants()) do
if v.Name == script.Parent.Value.Value then
plr.Character.PrimaryPart.Position = v.Position + Vector3.new(0,3,0) --[[ this right here is the problem.
you're trying to move the HumanoidRootPart (aka. PrimaryPart) with Position, instead of CFrame.]]
script.Parent.Decay:Play()
v.ProximityPrompt.Enabled = false
wait(3)
v.ProximityPrompt.Enabled = true
elseif v == nil then
animplay:Stop()
plr.Character.PrimaryPart.Anchored = false
end
end
script.Parent.ProximityPrompt.Enabled = true
plr.Character.PrimaryPart.Anchored = false
end
end)
This would be the code after fixing those errors, and I’ve cleaned it up for you so that it’s easier for everyone to read.
local ProximityPrompt = script.Parent.ProximityPrompt
local Decay = script.Parent:WaitForChild("Decay") -- assuming it's an animation, what is it for?
local Animation = script.Parent:WaitForChild("Animation") -- what's this for this as well??
local HoleName = script.Parent.Value.Value
ProximityPrompt.Triggered:Connect(function(plr)
local Character = plr.Character
local HumanoidRootPart = Character.PrimaryPart
ProximityPrompt.Enabled = false
if Character:FindFirstChild("Zombie") and Character:FindFirstChild("OldMan") then
local animplay = Character.Zombie:LoadAnimation(Animation)
HumanoidRootPart.Anchored = true
animplay:Play()
Decay:Play()
wait(6)
for i,v in pairs(workspace:GetDescendants()) do
if v.Name == HoleName then
local Hole = v
local hPrompt = v:WaitForChild("ProximityPrompt")
HumanoidRootPart.CFrame = CFrame.new(Hole.Position + Vector3.new(0,3,0)) -- we don't have to do any extra, since a CFrame just needs the position (a Vector3).
Decay:Play()
hPrompt.Enabled = false
wait(3)
hPrompt.Enabled = true
elseif v == nil then
animplay:Stop()
HumanoidRootPart.Anchored = false
end
end
ProximityPrompt.Enabled = true
HumanoidRootPart.Anchored = false
end
end)
That’s why I don’t use Cframe. When my character is teleports, he is anchored, and this hole lies on the surface and my player turns over as well and the animation works uncorrectly
No erros, the script is simply deleted and my character does not follow the following instructions in the script, but simply remains in the position in which the script made it. That is Anchored and animation playing
Oh wait, i think this work I just didn’t notice that you’re using the hole position there. I didn’t even think to do something like CFrame.new(hole.position + Vector3.new)
I’m fixed this. Just added in my character script:
while true do
for i,v in pairs(workspace:GetDescendants()) do
if v.Name == "hole1" then
v.Destroying:Connect(function()
for i,v in ipairs(script.Parent.Zombie:GetPlayingAnimationTracks()) do
v:Stop()
end
script.Parent.PrimaryPart.Anchored = false
end)
end
end
wait(0.1)
end