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

Tool:Clone().Parent = plr.StarterGear and parent to inventory folder Not Working?

so my clone to starter gear is not working and the parent to the inventory folder too any fix??? (Local Script)Code:

local plr = game.Players.LocalPlayer
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")--gets ReplicatedStorage
local ToolsFolder = ReplicatedStorage:FindFirstChild("Tools")-- gets the tools folder
local InventoriesFolder = ReplicatedStorage:FindFirstChild("Inventories")-- gets the inventories folder
local button = script.Parent-- gets the button
local SpeedCoil = ToolsFolder:FindFirstChild("SpeedCoil")
print("VariablesDone!")--prints "VariablesDone!"
--MainScript--
button.MouseButton1Click:Connect(function()--when a player presses the button in left click
	print("Pressed")-- when a player presses the button then it will print out "Pressed"
	local inventory_folder = InventoriesFolder[plr.Name]
	print("No Errror BRUH")
	SpeedCoil:Clone().Parent = plr.Backpack
	SpeedCoil:Clone().Parent = plr.StarterGear
	SpeedCoil:Clone().Parent = inventory_folder
	end)

ThankYou!

1 comment

0

Wait I know how to fix your problem.

2 answers

So I have a similar game, where I have tool gamepasses.

The problem your making is this:

Compare your code with mine.

local plr = game.Players.LocalPlayer
02	local Players = game:GetService("Players")
03	local ReplicatedStorage = game:GetService("ReplicatedStorage")--gets ReplicatedStorage
04	local ToolsFolder = ReplicatedStorage:FindFirstChild("Tools")-- gets the tools folder
05	local InventoriesFolder = ReplicatedStorage:FindFirstChild("Inventories")-- gets the inventories folder
06	local button = script.Parent-- gets the button
07	local SpeedCoil = ToolsFolder:FindFirstChild("SpeedCoil")
08	print("VariablesDone!")--prints "VariablesDone!"
09	--MainScript--
10	button.MouseButton1Click:Connect(function()--when a player presses the button in left click
11	    print("Pressed")-- when a player presses the button then it will print out "Pressed"
12	    local inventory_folder = InventoriesFolder[plr.Name]
13	    print("No Errror BRUH")
14	    SpeedCoil:Clone().Parent = plr.Backpack
15	    SpeedCoil:Clone().Parent = plr.StarterGear
16	    SpeedCoil:Clone().Parent = inventory_folder
17	    end)

Now check Mine:

local id = 10409444 
game:GetService("MarketplaceService").PromptGamePassPurchaseFinished:Connect(function(plr,ido,purchased)
    if purchased and ido == id then 
		game.ServerStorage.Tools.DiamondSword:clone().Parent = plr.Backpack		
    end
end)
game.Players.PlayerAdded:Connect(function(plr)
    plr.CharacterAdded:connect(function(char)
        if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(game.Players[char.Name].UserId, id) then
			game.ServerStorage.Tools.DiamondSword:clone().Parent = plr.Backpack		
        end
    end)
end)

Moderate this in your own way.

I don't have much experience with the StarterGear folder, but I assume that the server is cloning this folder to your backpack whenever a player spawns. As a result, attempting to put tools in StarterGear from the client may not work. You'd have to use a RemoteEvent.

local plr = game.Players.LocalPlayer
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")--gets ReplicatedStorage
local ToolsFolder = ReplicatedStorage:FindFirstChild("Tools")-- gets the tools folder
local InventoriesFolder = ReplicatedStorage:FindFirstChild("Inventories")-- gets the inventories folder
local button = script.Parent-- gets the button
local Tool = ToolsFolder:FindFirstChild("SpeedCoil")
local GiveToolRemote = ReplicatedStorage:WaitForChild("Tools"):WaitForChild("RemoteEvent")
print("VariablesDone!")--prints "VariablesDone!"
--MainScript--
button.MouseButton1Click:Connect(function()--when a player presses the button in left click
    print("Pressed")-- when a player presses the button then it will print out "Pressed"
    local inventory_folder = InventoriesFolder[plr.Name]
    print("No Errror BRUH")
    GiveToolRemote:FireServer(Tool.Name)
end)


--PUT THIS IN A SERVER SCRIPT IN SERVERSCRIPTSERVICE
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Tools = Instance.new("RemoteEvent", ReplicatedStorage.Tools)
local ToolsFolder = ReplicatedStorage:FindFirstChild("Tools")
local InventoriesFolder = ReplicatedStorage:FindFirstChild("Inventories")

Tools.OnServerEvent:Connect(function(player, Toolname)
	local Tool = ReplicatedStorage:FindFirstChild(Toolname)

	if Tool then
		Tool:Clone().Parent = player.StarterGear
		Tool:Clone().Parent = player.Backpack
	
		local inventory_folder = InventoriesFolder[player.Name]
		Tool:Clone().Parent = inventory_folder
	end
end)

33 comments

0

I Forgot The Error But It Gives Me A Error

0

Ok so uhh it gives me an error when i edit the script it red lines in line 21 in the serverscriptservice script

0

Oh, my bad, I overlooked the variable assignment. I edited the code; try now.

0

ok let me try it gtg to bed first

0

Sparks I Wanna Ask Something What If i want to buy different items what do i do?? thanks

0

Oh And Btw FireServer Is Not A Valid memeber Of A Folder

0

I updated the code snippet. You basically want to add a second parameter to the FireServer() with the tool name, and then look for the tool on the server to make sure it exists.

0

Fixed the remote issue as well

0

oh o k thanks!!

0

oof sorry but another one error Expected identifier when parsing expression, got ')' in line 16

0

Forgot to add an end to the last if statement lol

0

ok i fixed it

0

FireServer is Not A valid member Of A folder In Local Script

0

i Mean Infinite yield possible on 'ReplicatedStorage.Tools:WaitForChild("RemoteEvent")'

0

Updated again...

0

im very very sorry

0

i mean the local script in the button has the infinite yeild

0

Fixed It But Another problem in the local script in the button Players.Rgboffical_yt.PlayerGui.ScreenGui.Frame.Blue.LocalScript:15: attempt to index nil with 'FireServer'

0

Sparks Please Help me

0

Try again

0

line 8 in local script Infinite yield possible on 'ReplicatedStorage.Tools:WaitForChild("RemoteEvent")'

0

Did you use the new code I updated?

0

yes

0

the error is in the local script in the button Please help.Thanks

0

The code worked for me when I tested it just now. Something else is not functioning properly for you.

0

Does "Variables Done" still print?

0

Yes

0

I mean No It Does Not print "Variables Done"

0

I Checked Again. Should I Try ReCopiying The Code?? Like I Mean All?

0

Should I?

0

ok i tiried it AGAIN so it prints variables done BUT Argument 1 missing or nil, Script 'ServerScriptService.ToolGiver', Line 7

0

fixed again

0

Ok ill try TYSM For Ur Patience

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