hello i come to you with a problem that i can’t cope with.
namely (as the title says) I cannot check with the server script whether the tool is not in the player’s backpack or StarterGear.
I see this on the console: ‘Sword is not a valid member of StarterGear “Players.dkdntgn.StarterGear” - Server - Script:2’
I appreciate any help
script.Parent.GetTool.OnServerEvent:Connect(function(plr)
if game.ReplicatedStorage.Tools.Sword.Parent ~= plr.StarterGear then
game.ReplicatedStorage.Tools.Sword:Clone().Parent = plr.StarterGear
wait()
plr:LoadCharacter()
else
plr.StarterGear.Sword:Destroy()
end
end)
script.Parent.GetTool.OnServerEvent:Connect(function(plr)
if not game.ReplicatedStorage.Tools.Sword.Parent == plr.Backpack then
local clone = game.ReplicatedStorage.Tools.Sword:Clone()
clone.Parent = plr.Backpack
wait()
plr:LoadCharacter()
else
plr.Backpack.Sword:Destroy()
end
end)
this line checks if the parent of the sword in replicated storage is StarterGear, which doesnt really make sense to me since you already know its in replicated storage
You’re checking if the tool that is already parented to ReplicatedStorage is somehow parented to StarterGear, which is impossible. Instead you should check if there is a child of the StarterGear called Sword, using :FindFirstChild().
script.Parent.GetTool.OnServerEvent:Connect(function(plr)
if plr.StarterGear:FindFirstChild("Sword") then
plr.StarterGear.Sword:Destroy()
else
game.ReplicatedStorage.Tools.Sword:Clone().Parent = plr.StarterGear
task.wait()
plr:LoadCharacter()
end
end)
WaitForChild() yields the script until a certain child is loaded, so it would not be useful in this context. FindFirstChild() is used in this script to check if a child exists, not wait for one to exist. In this context it’s not just a case of replacing FindFirstChild with WaitForChild, but you can read more about that in the Creator Documentation link that I listed in my post above.