Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Inventory placement not following through?

Asked by
Ziffixture 6913 Moderation Voter Community Moderator
5 years ago
Edited 5 years ago

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!

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. Gey4Jesus69 2705 — 5y
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 Ziffixture 6913 — 5y
0
also didn't fix the issue Ziffixture 6913 — 5y
0
but i'll edit it so it doesn't check for the player you're right there Ziffixture 6913 — 5y
View all comments (12 more)
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 Gey4Jesus69 2705 — 5y
0
I know, but It's called being cautious, if someone exploits and removes a character, then what happens? Ziffixture 6913 — 5y
0
Anyway, could you help me fix this? Ziffixture 6913 — 5y
0
I posted the error Ziffixture 6913 — 5y
0
Its their fault for exploiting. Forget them. User#24403 69 — 5y
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. User#24403 69 — 5y
0
I'm just as confused rn Ziffixture 6913 — 5y
0
This is the full code Ziffixture 6913 — 5y
0
Oh, hmm Ziffixture 6913 — 5y
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 Ziffixture 6913 — 5y
0
So this is a silent output issue Ziffixture 6913 — 5y
0
I'm bad at those Ziffixture 6913 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

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.

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 Ziffixture 6913 — 5y
Ad

Answer this question