Yet I have no clue how to reference the player in a server script or if that’s even a possibility.
local players = game:GetService("Players")
local removeSwordEvent = game.ReplicatedStorage.RemoveSword
local toolSword = game.ReplicatedStorage.ClassicSword
removeSwordEvent.OnServerEvent:Connect(function(Player)
local player = players:GetPlayerFromCharacter(Player)
player.Character:FindFirstChild("ClassicSword"):Destroy()
end)
As you can see in the script I tried using GetPlayerFromCharacter instead of trying to get the local player but it still gives me back “nil” due to Character.
I’m pretty new but i’m pretty sure you need to access the player’s backpack. You are currently trying to destroy “ClassicSword” inside the character model.
Let me give you some tips about what you are trying to achieve.
If you want to destroy a players item then it could be stored in their backpack or in their character.
The tool is in the players backpack when the player doesn`t hold the tool in their hand.
But if the player activated the tool by holding it then it is in their character.
Also you already got the Player from the RemoveEvent.
removeSwordEvent.OnServerEvent:Connect(function(Player)
local player = players:GetPlayerFromCharacter(Player)
player.Character:FindFirstChild("ClassicSword"):Destroy()
end)
You don’t need this line:
local player = players:GetPlayerFromCharacter(Player)
Let me give you an improved script:
local players = game:GetService("Players")
local removeSwordEvent = game.ReplicatedStorage.RemoveSword
removeSwordEvent.OnServerEvent:Connect(function(Player)
if Player.Backpack:FindFirstChild("ClassicSword") then -- checks if the tool is in the players backpack
Player.Backpack:FindFirstChild("ClassicSword"):Destroy()
else -- if it's not in the backpack then it must be in the character!
Player.Character:FindFirstChild("ClassicSword"):Destroy()
end
end)