I want the character’s inventory contents that was transfered to “FakeBackpack” beforehand, (that part of the script functions well.) to return to the Player’s backpack. However, I keep getting this error: "
https://gyazo.com/0e082d4b414a56d20eb8a3cba1c30bbc
I’ve looked up solutions and one of them said that their script did not define the right thing, I’ve looked in the script and I don’t see anything out of the normal.
Note: I am not the smartest individual, so sorry if this post comes across as vague or stupid.
What I am trying to get is the character’s player, (which strangely it does when state == cuff) but shows an error in the output window, which I am assuming is the cause for this.
Script:
--[[
Made By Matthew_Plays55
Please do not delete the credits if you reupload. Thanks!
]]
local RemoteEvent = script.Parent:WaitForChild("RemoteEvent")
local TargetTorso = nil
local Using = false
local sound = script.Parent:WaitForChild("Sound")
function CheckForTargetTorso(part)
if part.Parent:IsA'Model' and part.Parent:FindFirstChildOfClass'Humanoid' then
local char = part.Parent
local torso
if char:FindFirstChild'Torso' then
torso = char.Torso
elseif char:FindFirstChild'HumanoidRootPart' then
torso = char.HumanoidRootPart
end
return char, torso
end
end
function CheckForTorso(player)
local Char = player.Character
if Char:FindFirstChild'Torso' then
return Char.Torso
else
return Char.HumanoidRootPart
end
end
RemoteEvent.OnServerEvent:Connect(function(player, state, part)
local Character = game.Players:GetPlayerFromCharacter(part.Parent)
--above is the line that causes the error.
if state == 'Cuff' then
local target = nil
local playerTorso = nil
target, TargetTorso = CheckForTargetTorso(part)
playerTorso = CheckForTorso(player)
if target then
Using = true
RemoteEvent:FireClient(player, 'Use')
spawn(function()
if Using then
TargetTorso.Anchored = true
local hum = TargetTorso.Parent:WaitForChild("Humanoid")
local FBK = TargetTorso.Parent:WaitForChild("FakeBackpack")
hum:UnequipTools()
for _,v in pairs(Character.Backpack:GetChildren()) do
v.Parent = FBK
end
local soundclone = sound:Clone()
soundclone.Parent = TargetTorso
soundclone.PlayOnRemove = true
soundclone:Destroy()
end
while Using and wait() do
TargetTorso.CFrame = playerTorso.CFrame * CFrame.new( 0, 0, -6.5 )
end
end)
end
elseif state == 'UnCuff'then
local target = nil
local playerTorso = nil
TargetTorso.Anchored = false
local FBK = TargetTorso.Parent:WaitForChild("FakeBackpack")
local backpack = Character:WaitForChild("Backpack")
for _,v in pairs(FBK:GetChildren()) do
v.Parent = backpack
end
Using = false
wait()
end
end)
Local script it fires to
--[[
Made By Matthew_Plays55
Please do not delete the credits if you reupload. Thanks!
]]
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local Tool = script.Parent
local Using = false
local RemoteEvent = script.Parent:WaitForChild("RemoteEvent")
Tool.Activated:Connect(function()
if not Using then
if Mouse.Target then
RemoteEvent:FireServer('Cuff', Mouse.Target)
end
else
Using = false
RemoteEvent:FireServer('UnCuff')
end
end)
RemoteEvent.OnClientEvent:Connect(function( state )
if state == 'Use' then
Using = true
end
end)
If you are confused, please let me know what I can do to help you understand.
EDIT: Forgotten to remove the “–” from the parts that don’t work, they should be fixed now.