My script :
local Player = game:GetService("Players").LocalPlayer local Character = Player.Character or Player.CharacterAdded:Wait() local Humanoid = Character:FindFirstChildOfClass("Humanoid") game.ReplicatedStorage.ToolGive.OnServerEvent:Connect(function(player) --checks for event local tool = game.Lighting.DarkSword:Clone() --gets tool tool.Parent = game.Players.LocalPlayer:FindFirstChild("Backpack") --gives tool end) --ends lol
: This is supposed to give you a weapon, the first three lines i added because the backpack wouldnt load in and apparently you need the give the character time to load in.
I keep getting either 3 of the following errors:
Attempt to index nil with character Attempt to index nil with backpack Attempt to index nil with FindFirstChild
I have no idea what to do at this point, ive been trying to fight this bug for like 2 hours. Any insight would be appreciated.
So, from Line 4
, it looks like it is Server Script. But LocalPlayer
is not supported for Server/Normal scripts. LocalPlayer
is only for LocalScripts.
Also, if you are confused on how you can get the player. Well, its simple, you are receiving remote event fired from Client Side, so the player parameter you have in the function, that is your player.
So fix that :
game.ReplicatedStorage.ToolGive.OnServerEvent:Connect(function(player) local tool = game.Lighting.DarkSword:Clone() tool.Parent = player:WaitForChild("Backpack") -- Gets the backpack of the player, who fired the remote event end)
Lemme know if it helps!