04:24:52.801 Backpack is not a valid member of MeshPart "Workspace.Battery" - Server - PickUpScript:13
Inside the pickupBattery function the batteryCloneâs Parent needs to be set to player.Backpack, you have it set to Tool.Backpack.
This is how it should be:
local function pickupBattery()
local batteryClone = Tool:Clone()
batteryClone.Parent = player.Backpack
end
It is giving me this error â 04:30:36.289 Workspace.Map.KillArea.Batteries.Battery.PickUpScript:13: attempt to index nil with 'Backpack' - Server - PickUpScript:13
Wait is this in a local script or server script? You donât have a player variable for that function. Either way, if you pass the Player parameter from the ProximityPromptâs Triggered event to the pickupBattery function that will work.
Here is what the new code would look like:
local ToolNames = {"Battery"} -- Change Item to your item name and move it to ServerStorage
local Storage = game.ServerStorage.RareItems
local Part = script.Parent
local ProximityPrompt = Part:WaitForChild("ProximityPrompt")
local folder = workspace.Map.Zones.BatteryZone
local tool = game.Workspace.Map.KillArea.Batteries.Battery
local function pickupBattery(Player)
local batteryClone = Tool:Clone()
batteryClone.Parent = Player.Backpack
end
local function moveBattery()
local toolSpawns = folder:GetChildren()
Tool.CFrame = toolSpawns[math.random(1,#toolSpawns)].CFrame + Vector3.new(0,1,0) --//Picks one random spawn's CFrame with Y offset of 1 stud.
end
ProximityPrompt.Triggered:connect(function(Player)
if Player and Player.Character then
local Backpack = Player:WaitForChild("Backpack")
for i = 1, #ToolNames do
local Tool = Storage:FindFirstChild(ToolNames[i])
if Tool then
if Backpack:FindFirstChild(Tool.Name) == nil then
moveBattery()
pickupBattery(Player)
end
end
end
end
end)
This is a ServerScript it is in Workspace.
How about we make it that when the Player gets the Battery it will Destroy() the current Battery (the Battery the Players has just achieved) and wait (1) then the Battery will Spawn in a different area.
If so you may proceed here to a new Topic â
How to Make a Randomized Item Spawner - Help and Feedback / Scripting Support - Developer Forum | Roblox
I ended up fixing everything associating with the Flashlight.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.