Hello im making a jojo game and heres the script so far as we dont have more than 1 stand implemented so far theres only king crimson so heres the script :
local Arrow = script.Parent
local Stands = game.ServerStorage.Stands
local KingCrimson = Stands.KingCrimson
local Players = game:GetService(“Players”)
local Player = Players.LocalPlayer
local Backpack = Player.Backpack
Arrow.Activated:Connect(function()
KingCrimson:Clone()
KingCrimson.parent = Backpack
end)
but for some reason i get this error message?
Players.3th4n328.Backpack.Arrow.ArrowScript:7: attempt to index nil with ‘Backpack’
First off, since this a localscript (im assuming) you can’t access ServerStorage, that’s server only.
For something like this, you would store in objects in ReplicatedStorage
local Stands = game:GetService("ReplicatedStorage").Stands -- use ReplicatedStorage instead
local Arrow = script.Parent
local Stands = game:GetService("ReplicatedStorage").Stands -- or you can do "game.ReplicatedStorage.Stands"
local KingCrimson = Stands.KingCrimson
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Backpack = Player.Backpack
Arrow.Activated:Connect(function()
local obj = KingCrimson:Clone() -- save the cloned object to a variable
obj.Parent = Backpack -- capital "P" for parent
end)
@Ulxqra game:GetService("Players") is a service, not an Instance, you don’t need WaitForChild
After looking at this a second time, I realized you are using a Server Script. You can’t access LocalPlayer from a server script. To do that, you would need to utilize Remote Events.
-- local script
local Arrow = script.Parent
local Remote = -- create a new remote event instance and put the path to it here
Arrow.Activated:Connect(function()
Remote:FireServer() -- send a request to the server to get the item
end)
-- server script
local Stands = game:GetService("ServerStorage").Stands
local KingCrimson = Stands.KingCrimson
local Remote = -- input the remote event's path here
Remote.OnServerEvent:Connect(function(player) -- the player who fired it is automatically passed
local Backpack = player.Backpack
local obj = KingCrimson:Clone()
obj.Parent = Backpack
end)