Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Inventory placement not following through?

There are probably a lot more to come with my Universal Inventory Script, but right now I just need to focus on one issue. Cloning the Inventories into the proper places. There are two types of Inventories, inventory; located in player, & carrierInventory; located in character.

inventory clones into player but carrierInventory doesn't clone into the character. The Script is also supposed to dispose of itself once finished cloning, it appears it's a silent output issue judging by the Script obviously not following through with the disposal command, of which isn't interrupted by anything.

I can't seem to find the issue, can you?

Players.simplealgorithm.PlayerScripts.pickUpItem:46: attempt to index upvalue 'carrierInventory' (a nil value)

I moved the parent to starterCharacter and I got this

'Something unexpectedly tried to set the parent of setInventories to NULL while trying to set the parent of setInventories. Current parent is carrierInventory.'?

local player = game:GetService("Players").LocalPlayer
local character = player.Character or player.CharacterAdded:wait()
if (character) then
	local inventory = script:FindFirstAncestor("inventory")
	local carrierInventory = inventory:WaitForChild("carrierInventory")
	if not player:FindFirstChild("inventory") then
		inventory:Clone().Parent = player
		player:FindFirstChild("inventory"):ClearAllChildren()
	elseif not character:FindFirstChild("carrierInventory") then
		carrierInventory:Clone().Parent = character
		character:FindFirstChild("carrierInventory"):ClearAllChildren()
	end
end
script:Destroy()

Thanks!

16 comments

0

u dont have to check for player; local player will never be nil as long as its in a local script. you also dont have to check for character, bc :Wait() will make the script yield until character is found, kinda like :WaitForChild() therefore, it will never be nil if the script continues.

0

It's my decision, it's also important if the Character exists because it's mainly based of the Character, so I'd be happy to yield it until it exits

0

also didn't fix the issue

0

but i'll edit it so it doesn't check for the player you're right there

0

i know its ur decision, but ur decision should be to make ur code as efficient as possible. the character will always exist, so that if statement is completely pointless

0

I know, but It's called being cautious, if someone exploits and removes a character, then what happens?

0

Anyway, could you help me fix this?

0

I posted the error

0

Its their fault for exploiting. Forget them.

0

You should also post some full code, as this is not what an upvalue is. An upvalue is an external local variable declared outside of a function body. This is not a function body.

0

I'm just as confused rn

0

This is the full code

0

Oh, hmm

0

It's in the other Script, I fixed a syntaxing issue, but it was right, it can't find it because it's not in character, it wasn't cloned

0

So this is a silent output issue

0

I'm bad at those

1 answer

Okay so the answer to your first issue of why carrierInventory wasn't cloned into character was because you put that in an elseif block. This error makes the code either clone inventory into player, or if there's already an inventory there, it clones carrierInventory into character. It only does one or the other. In short, just change that elseif to if.

I don't know why the second issue is occurring, but it might be because of the first issue. If the script still being there still bothers you after the first fix, you can comment on my post for more help, or you can maybe try to disable the script using script.Disabled = true and that might help a bit.

1 comment

0

I already fixed my issue, thanks for the try though, also I had tried switching the statements, did nothing. I bailed the Script and decided to do the Cloning in the MainScript

This discussion is preserved as it was. New answers, comments, and votes are closed.