I wanna get the location thoughout the module where the item is, then copies the item to the player’s backpack. At the moment i get a error on line 35.
The issue i am currently facing is that he cannot copy the item. I have tried certain prints to find out the issue but I cannot put my finger on it what the issue is. I know it can find the item but it just does not wanna copy it over to the player’s inventory.
The item that should give the player a item when you touch it:
--- services
local playerService = game:GetService("Players")
--- locations
local LootboxSystemFolder = game.ReplicatedStorage.LootboxSystemFolder
local model = script.Parent
--- module locations & gear folder olcation
local LootboxSystemModule = require(LootboxSystemFolder.LootboxSystemModule)
local ItemFolder = game.ReplicatedStorage.LootboxSystemFolder.Gears
--local mathrandom = math.random(1,4)
local mathrandom = 1
---inside module locations
local recievedInfoOfItemFromGearFolder = LootboxSystemModule.Lootboxes["[1]NeutralBox"]["BoxItem" .. mathrandom].Item
local recievedInfoOfItemName = LootboxSystemModule.Lootboxes["[1]NeutralBox"]["BoxItem" .. mathrandom].Name
local boxChosen = LootboxSystemModule.Lootboxes["[1]NeutralBox"]["BoxItem" .. mathrandom]
local function ModelTouched(touchedpart)
local character = touchedpart.parent
local debounce = false
local humanoid = character:FindFirstChildWhichIsA("Humanoid")
if humanoid and debounce == false then
debounce = true
local player = playerService:GetPlayerFromCharacter(character)
--print(boxChosen)
--print(recievedInfoOfItemFromGearFolder)
if recievedInfoOfItemFromGearFolder ~= nil then
--print("Found item")
local recievedInfoOfItemFromGearFolder2 = LootboxSystemModule.Lootboxes["[1]NeutralBox"]["BoxItem" .. mathrandom].Item
local getGear = ItemFolder.recievedInfoOfItemFromGearFolder2:Clone()
getGear = player.Backpack
--recievedInfoOfItemFromGearFolder2.parent = character.parent
elseif recievedInfoOfItemFromGearFolder == nil then
print("Could not find content to give on the Item: ".. recievedInfoOfItemName)
end
debounce = false
--model:Destroy()
end
end
model.Touched:Connect(ModelTouched)
What error appears?
(also, .Touched events don’t work on models)
It would give me a better judgement for the script if you could tell me the error but try this:
--//Services
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
--//Modules
local LootboxSystemModule = require(ReplicatedStorage.LootboxSystemFolder.LootboxSystemModule)
--//Variables
local LootboxSystemFolder = ReplicatedStorage.LootboxSystemFolder
local ItemFolder = LootboxSystemFolder.Gears
local Part = script.Parent
--//Controls
local debounce = false
--local RandomNumber = Random.new():NextInteger(1, 4)
local randomNumber = 1
local recievedInfoOfItemFromGearFolder = LootboxSystemModule.Lootboxes["[1]NeutralBox"]["BoxItem" .. randomNumber].Item
local recievedInfoOfItemName = LootboxSystemModule.Lootboxes["[1]NeutralBox"]["BoxItem" .. randomNumber].Name
local boxChosen = LootboxSystemModule.Lootboxes["[1]NeutralBox"]["BoxItem" .. randomNumber]
--//Functions
Part.Touched:Connect(function(hit)
local Player = Players:GetPlayerFromCharacter(hit.Parent)
if not Player or debounce then
return
end
debounce = true
if recievedInfoOfItemFromGearFolder then
local recievedInfoOfItemFromGearFolder2 = LootboxSystemModule.Lootboxes["[1]NeutralBox"]["BoxItem" .. randomNumber].Item
local newGear = recievedInfoOfItemFromGearFolder2:Clone()
newGear.Parent = Player.Backpack
else
print("Could not find content to give on the Item: ".. recievedInfoOfItemName)
end
debounce = false
end)
I’m just mirrorally confused why it would work now as I did use gear.parent and player.backpack, also pretty curious what the diffrent is between math.random and Random.new():NextInteger(number,number). Cause it seems to be math.random be with extra steps?
Also apologies for leaving some info out, error was related to copying to the player inventory as apparently gear.parent wouldn’t work (but did work for me in past).
Ah i see, ye my apologies. Been so busy scripting that I made this minor mistake and did not even see it myself. I’m happy you could figure it out, it means alot!
And about random.new() and math.random, welp I know math.random is pretty old as I used it around 2013 or even 2014. However I notice that if you try to print random.new() it wouldn’t give any value and just print random until you type :nextinteger.
Probably an offtopic one but, do you desire to be friends? I gladly learn more from you and like to know you better. Ofcourse depends on you, I understand if you do not desire that!