Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

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

Asked by 15 days ago

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!

0
Wait I know how to fix your problem. XLeMysterioX 22 — 15d

2 answers

Log in to vote
0
Answered by 15 days ago

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.

Ad
Log in to vote
0
Answered by
Sparks 534 Moderation Voter
15 days ago
Edited 14 days ago

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)
0
I Forgot The Error But It Gives Me A Error Rgboffical_yt 11 — 14d
0
Ok so uhh it gives me an error when i edit the script it red lines in line 21 in the serverscriptservice script Rgboffical_yt 11 — 14d
0
Oh, my bad, I overlooked the variable assignment. I edited the code; try now. Sparks 534 — 14d
0
ok let me try it gtg to bed first Rgboffical_yt 11 — 14d
View all comments (29 more)
0
Sparks I Wanna Ask Something What If i want to buy different items what do i do?? thanks Rgboffical_yt 11 — 14d
0
Oh And Btw FireServer Is Not A Valid memeber Of A Folder Rgboffical_yt 11 — 14d
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. Sparks 534 — 14d
0
Fixed the remote issue as well Sparks 534 — 14d
0
oh o k thanks!! Rgboffical_yt 11 — 14d
0
oof sorry but another one error Expected identifier when parsing expression, got ')' in line 16 Rgboffical_yt 11 — 14d
0
Forgot to add an end to the last if statement lol Sparks 534 — 14d
0
ok i fixed it Rgboffical_yt 11 — 14d
0
FireServer is Not A valid member Of A folder In Local Script Rgboffical_yt 11 — 14d
0
i Mean Infinite yield possible on 'ReplicatedStorage.Tools:WaitForChild("RemoteEvent")' Rgboffical_yt 11 — 14d
0
Updated again... Sparks 534 — 14d
0
im very very sorry Rgboffical_yt 11 — 14d
0
i mean the local script in the button has the infinite yeild Rgboffical_yt 11 — 14d
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' Rgboffical_yt 11 — 14d
0
Sparks Please Help me Rgboffical_yt 11 — 14d
0
Try again Sparks 534 — 14d
0
line 8 in local script Infinite yield possible on 'ReplicatedStorage.Tools:WaitForChild("RemoteEvent")' Rgboffical_yt 11 — 14d
0
Did you use the new code I updated? Sparks 534 — 14d
0
yes Rgboffical_yt 11 — 14d
0
the error is in the local script in the button Please help.Thanks Rgboffical_yt 11 — 14d
0
The code worked for me when I tested it just now. Something else is not functioning properly for you. Sparks 534 — 14d
0
Does "Variables Done" still print? Sparks 534 — 14d
0
Yes Rgboffical_yt 11 — 14d
0
I mean No It Does Not print "Variables Done" Rgboffical_yt 11 — 14d
0
I Checked Again. Should I Try ReCopiying The Code?? Like I Mean All? Rgboffical_yt 11 — 14d
0
Should I? Rgboffical_yt 11 — 14d
0
ok i tiried it AGAIN so it prints variables done BUT Argument 1 missing or nil, Script 'ServerScriptService.ToolGiver', Line 7 Rgboffical_yt 11 — 14d
0
fixed again Sparks 534 — 14d
0
Ok ill try TYSM For Ur Patience Rgboffical_yt 11 — 14d

Answer this question