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)