My riot script has no errors and it doesn't work

I have made a tool that fires a RemoteEvent, The riot script is in the serverscriptservice and when the tool is activated a script is starterplayerscripts fires another remoteevent, The script in serverscriptservice fires
on the second remoteevent’s OnServerEvent. There are no errors and it doesnt give the tool to the player, Please help me this is the script:

local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local player = game.Players.LocalPlayer
local EventFolder = ReplicatedStorage:WaitForChild("Events2")
local RiotEvent = EventFolder:WaitForChild("Riot")
local Weapon = ServerStorage:WaitForChild("AK")

           local weaponclone = Weapon:Clone()
 Weapon.Parent = player.BackPack

First off, where is this LocalScript located? LocalScripts only run when they are a descendant of the player’s PlayerScripts, the players character, the players backpack, the player’s PlayerGui, and ReplicatedFirst. If you haven’t, move the LocalScript to one of these.

Secondly, ServerStorage isn’t replicated to the client, so you can’t access any of it’s children from LocalScripts, only from server scripts.

Thirdly, you can’t use OnServerEvent in LocalScripts, you have to switch it for an OnClientEvent, and get rid of the ‘player’ parameter.

Fourthly, you’re cloning a weapon, but you parent the original weapon to the player’s backpack, and then destroying the clone after 20 seconds. I’m pretty sure this is not what you want to do, because the clone is used for nothing.

The localscript is located in playerscripts, I’m accessing serverstorage from this script which is in serverscriptservice. The onserverevent is in the script which is in serverscriptservice

From what you’ve shown, the OnServerEvent is in the LocalScript, and you’re accessing ServerStorage from the LocalScript.

The local script in playerscripts fires the riotevent to the server, And this script that i’ve posted is in serverscriptservice accessing serverstorage.

LocalPlayer will always result in nil on the server.

Use the player’s name in a :GetPlayers() function to find the player and then parent the tool to the
player’s backpack.

Then why is Players.LocalPlayer in the script?

Never mind i figured out that if i just do
“local player = players:getplayers()” it’ll work aswell, Thank you!

If it has no errors and you’re sure the following conditions are met:

  • The script is in ServerScriptService
  • The script is enabled (not disabled)
  • The script runs on the event

Then it seems like you’re parenting to nil, as there is no property on the Player instance called BackPack; instead, it is called Backpack. You’re able to parent things to nil, which (I think) is somewhat the same as using :Destroy()

Do this and it should work

weaponclone.Parent = player.Backpack;

EDIT: I saw you had several mistakes now.

The OnServerEvent gives one fixed argument, which is the player, it seems like you forgot about it!
Remove the local player = game.Players.LocalPlayer as it will be nil on the server.

The script should then be similar to this:

.OnServerEvent:Connect(function (player)
    local weaponClone = Weapon:Clone();
    weaponClone.Parent = player.Backpack;

Players | Documentation - Roblox Creator Hub has 2 examples for the function.