Tool Part Does Not Appear

Hello, so I have a sword fight area, and when I step on, then step off the carpet part doesn’t exists giving me this error 19:51:57.475 CarpetPart is not a valid member of Tool "Players.5Flipz.Backpack.MagicCarpet" - Server - Server:10

How do I fix this?

SwordEvent

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")

local TouchEvent = ReplicatedStorage:WaitForChild("ToolEvent")

game.Players.PlayerAdded:Connect(function(Player)
	local Folder = Instance.new('Folder')
	Folder.Name = Player.Name.. "'s Tools"
	Folder.Parent = game.ReplicatedStorage
end)

local function FireRemote(plr,val,item)
	if val == 'steppedOn' then
		local Character = plr.Character
		for i,v in pairs(Character:GetChildren()) do
			if v:IsA('Tool') then
				v.Parent = game.ReplicatedStorage[plr.Name.. "'s Tools"]
			end
		end
		for i,v in pairs(plr.Backpack:GetChildren()) do
			if v.Name ~= item.Name then
				if game.ReplicatedStorage[plr.Name.. "'s Tools"] then
					v.Parent = game.ReplicatedStorage[plr.Name.. "'s Tools"]
				end
			end
		end
		local NewWEAPON = item:Clone()
		NewWEAPON.Parent = plr.Backpack
		Character.Humanoid:EquipTool(NewWEAPON)
	elseif val == 'steppedOff' then
		local Character = plr.Character
		for i,v in pairs(Character:GetChildren()) do
			if v then
				if v:IsA('Tool') then
					if v.Name == item.Name then
						v:Destroy()
					end
				end
			end
		end
		for i,v in pairs(plr.Backpack:GetChildren()) do
			if v then
				if v:IsA('Tool') then
					if v.Name == item.Name then
						v:Destroy()
					end
				end
			end
		end
		for i,tool in pairs(game.ReplicatedStorage[plr.Name.. "'s Tools"]:GetChildren()) do -- now we get all our tools back
			tool.Parent = plr.Backpack
		end
	end
end

TouchEvent.OnServerEvent:Connect(FireRemote)

game.Players.PlayerRemoving:Connect(function(Player)
	if game.ReplicatedStorage:FindFirstChild(Player.Name.. "'s Tools") then
		game.ReplicatedStorage:FindFirstChild(Player.Name.. "'s Tools"):Destroy()
	end
end)

Server

-- Made by xuN8
-- Last updated May 27, 2021

-- Stuff in here is just for the special effects; go to Client script for the main code
-- For quick modifications, check the tool properties for attributes

local TweenService = game:GetService('TweenService')
local tool = script.Parent
local Triggered = tool.Triggered
local carpetPart = tool.CarpetPart
local sonicBoom = carpetPart.SonicBoomPart.SonicBoomEffect
local burst = carpetPart.Burst
local hrpOffset = carpetPart.RootPartOffset


local tweenInfo = TweenInfo.new(0.5, Enum.EasingStyle.Cubic, Enum.EasingDirection.Out)
local sonicBoomTween = TweenService:Create(sonicBoom, tweenInfo, {Radius = 30, InnerRadius = 30})
-- this will be used to attach the carpetPart to the player character
local weld = Instance.new('Weld', carpetPart)

local function showCarpet(bool)
	burst.Enabled = false
	sonicBoom.Visible = false
	carpetPart.Parent = bool and tool or game.ServerStorage
end

local function onEquip()
	local character = tool.Parent
	local hrp = character:FindFirstChild('HumanoidRootPart')
	if not hrp then return end
	
	-- attach carpetPart to humanoid rootpart
	weld.Part1 = hrp
	weld.C0 = CFrame.new()
	weld.C1 = hrpOffset.CFrame:Inverse()
	weld.Enabled = true
	
	showCarpet(true)
end

local function onUnequip()
	weld.Enabled = false
	showCarpet(false)
end

local function onActivate()
	-- show effects
	burst.Enabled = true
	sonicBoom.Visible = true
	sonicBoom.InnerRadius = 0
	sonicBoom.Radius = 15
	-- play the sonic boom tween and wait for it to finish
	sonicBoomTween:Play()
	sonicBoomTween.Completed:Wait()
	-- hide effects
	burst.Enabled = false
	sonicBoom.Visible = false
end

tool.CircularProgress.Enabled = false
weld.Part0 = carpetPart
weld.Enabled = false
showCarpet(false)

if tool:GetAttribute('SonicBoom') then Triggered.OnServerEvent:Connect(onActivate) end
tool.Equipped:Connect(onEquip)
tool.Unequipped:Connect(onUnequip)
1 Like

this error means there’s no instance named “CarpetPart” in your tool. check if there’s any instance named “CarpetPart” inside the “MagicCarpet” tool from the explorer.

So originally there is, however when I step in then out, that part gets removed and im not sure why. Thats what Im trying to fix

what do you mean step in step out? is it a tool that you obtain from touching a part?

No its basically the highlighted part. So before you step in you could have some tools from a shop. Then when you step in, you get a sword and only a sword, when you step out you get your original tools back. If the player has a MagicCarpet like me, the part isnt there causing me to get that error

i’m not sure what you mean, but is the tool instantly obtained from spawn or you have to do some interaction? plus, when you mean “originally there is” does the “CarpetPart” already exists before you play test?

No, you only have it if you have this gamepass which means the error doesnt effect anyone unless you have the gamepass, and the magic carpet equipped. You can equip the carpet from the shop

The problem could be because when you step out the box, you’re deleting the carpetPart and not something else

I didn’t make either script, so where would it be deleted?

I don’t know, there might be a script removing or changing the carpetPart’s parent, and so when you check for the part, it gives you an error

Also try using a WaitForChild

local carpetPart = tool:WaitForChild("CarpetPart")

I just get an infinite yield 22:06:08.901 Infinite yield possible on 'Players.5Flipz.Backpack.MagicCarpet:WaitForChild("CarpetPart")' - Studio

I believe this might be caused by carpetPart.Parent = bool and tool or game.ServerStorage.

Can you check if the carpetPart is parented to ServerStorage after you leave the zone to confirm this is the problematic code? (You will need to check on the server side)

image
Ah yeah it is there on the server side. How would I fix this?

1 Like

Change the line carpetPart.Parent = bool and tool or game.ServerStorage to this and tell me if it works:

if bool then
	carpetPart.Parent = tool
else
	carpetPart.Parent = game.ServerStorage
end

Nope, still getting the error on line 10 saying CarpetPart is not a valid member of Tool "Players.5Flipz.Backpack.MagicCarpet" - Server - Server:10

line 10

local carpetPart = tool.CarpetPart

The part will be completely thrown into the void if it isn’t welded to the handle and CanCollide is off. Have you checked your welds?

Its a scripting error not welding

Any other solutions that could work?

So is the carpetPart still in ServerStorage or did it disappear?

It clones into serverStorage twice with your script, once with the old.

image