Why does my script break after the first use?

  1. What do you want to achieve? a script that pushes people back in the player’s vicinity (the whole script is done but there’s an issue on line 35

  2. What is the issue? the error says ServerScriptService.Deleatur:35: attempt to index nil with 'IsA' the second time, but it was able to read it the first time.

  3. What solutions have you tried so far? none, this is confusing.

here’s my script

local Animation = Instance.new("Animation")
Animation.AnimationId = "rbxassetid://7883741018"


game.Players.PlayerAdded:Connect(function(Player)
	local debounce = false
	Player.CharacterAdded:Connect(function(Character)
		local Humanoid = Character:WaitForChild("Humanoid")
		Player.Chatted:Connect(function(msg)
			local spell = string.lower(msg)
			if spell == "deleatur" and not debounce then
				local practitioner = Character:FindFirstChild("Practitioner")
				if practitioner.Value == true then
					local magic = Character:FindFirstChild("Magic")
					if magic.Value > 50 then
						print("enough magic")
						debounce = true
						local Anim = Character:WaitForChild("Humanoid"):LoadAnimation(Animation)
						Anim:Play()
						wait(0.1)
						
						local check = Instance.new("Part")
						check.Shape = Enum.PartType.Cylinder
						check.Orientation = Vector3.new(0,0,90)
						check.Position = Character.HumanoidRootPart.Position
						check.Size = Vector3.new(6.63, 21.664, 21.664)
						check.Anchored = true
						check.CanCollide = false
						check.Name = Character.Name.."'s check part"
						check.Transparency = 1
						check.Parent = workspace
						print("made part")
						
						check.Touched:Connect(function(target)
							if target.Parent:IsA("Model") then -- the part that errors								if target.Parent.Name == Character.Name then return end
								
								local cf = CFrame.lookAt(target.Parent.HumanoidRootPart.Position, Character.HumanoidRootPart.Position)
								target.Parent.HumanoidRootPart.CFrame = cf
								
								target.Parent.Humanoid:ChangeState(Enum.HumanoidStateType.Physics)
								
								for index, joint in pairs(target:GetDescendants()) do
									if joint:IsA("Motor6D") then
										local socket = Instance.new("BallSocketConstraint")
										local a1 = Instance.new("Attachment")
										local a2 = Instance.new("Attachment")
										a1.Parent = joint.Part0
										a2.Parent = joint.Part1
										socket.Parent = joint.Parent
										socket.Attachment0 = a1
										socket.Attachment1 = a2
										a1.CFrame = joint.C0
										a2.CFrame = joint.C1
										socket.LimitsEnabled = true
										socket.TwistLimitsEnabled = true
										joint.Enabled = false
										task.wait(0.3)
										joint.Enabled = true
									end
								end
								
								local bv = Instance.new("BodyVelocity")
								bv.Velocity = target.Parent.HumanoidRootPart.CFrame.LookVector * -50
								bv.Parent = target
								wait(0.3)
								bv:Destroy()
								target.Parent.Humanoid:ChangeState(Enum.HumanoidStateType.GettingUp)
							end
						end)
						wait(0.2)
						check:Destroy()
					end
				end
			end
			wait(5)
			debounce = false
			print("can work now")
		end)
	end)				
end)



Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

What does this do? It looks like it destroys the script, try deleting that line.

this destroys the part that check to see what player’s are touching, it has nothing to do with the script
itself

1 Like

If you read the code, check is a variable used for the part.

1 Like
local Players = game:GetService("Players")
local Animation = Instance.new("Animation")
Animation.AnimationId = "rbxassetid://7883741018"
local debounce = false

Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		local Humanoid = Character:WaitForChild("Humanoid")
		local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
		local Animator = Humanoid:WaitForChild("Animator")
		Player.Chatted:Connect(function(msg)
			local spell = string.lower(msg)
			if spell == "deleatur" then
				if Character:FindFirstChild("Practitioner").Value then
					local magic = Character:FindFirstChild("Magic")
					if magic.Value >= 50 then
						if debounce then
							return
						end
						debounce = true
						local Anim = Animator:LoadAnimation(Animation)
						Anim:Play()
						task.wait(1)
						local check = Instance.new("Part")
						check.Shape = Enum.PartType.Cylinder
						check.Orientation = Vector3.new(0,0,90)
						check.Position = Character.HumanoidRootPart.Position
						check.Size = Vector3.new(6.63, 21.664, 21.664)
						check.Anchored = true
						check.CanCollide = false
						check.Name = Character.Name.."'s check part"
						check.Transparency = 1
						print("made part")
						check.Touched:Connect(function(target)
						check.Parent = workspace
							if target.Parent:FindFirstChild("HumanoidRootPart") and target.Parent.Name ~= Character.Name and target.Parent ~= Character then
								local targetHmr = target.Parent:WaitForChild("HumanoidRootPart")
								local targetHum = target.Parent:WaitForChild("Humanoid")
								local cf = CFrame.lookAt(targetHmr.Position, HumanoidRootPart.Position)
								targetHmr.CFrame = cf
								targetHum:ChangeState(Enum.HumanoidStateType.Physics)
								for index, joint in pairs(target:GetDescendants()) do
									if joint:IsA("Motor6D") then
										local socket = Instance.new("BallSocketConstraint")
										local a1 = Instance.new("Attachment")
										local a2 = Instance.new("Attachment")
										a1.Parent = joint.Part0
										a2.Parent = joint.Part1
										socket.Parent = joint.Parent
										socket.Attachment0 = a1
										socket.Attachment1 = a2
										a1.CFrame = joint.C0
										a2.CFrame = joint.C1
										socket.LimitsEnabled = true
										socket.TwistLimitsEnabled = true
										joint.Enabled = false
										task.wait(0.5)
										joint.Enabled = true
									end
								end
								local bv = Instance.new("BodyVelocity")
								bv.Velocity = targetHmr.CFrame.LookVector * -50
								bv.Parent = target
								task.wait(0.5)
								bv:Destroy()
								targetHum:ChangeState(Enum.HumanoidStateType.GettingUp)
							end
						end)
						task.wait(0.5)
						check:Destroy()
					end
				end
			end
			task.wait(0.5)
			debounce = false
		end)
	end)				
end)