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

How To Add Custom Value on FindFirstChild()?

1.Whats Your Problem?

So i have this simple script:

local Data = script.Parent.Parent.CurrentSelection
local Search = Data.ToolName.Value
local Price = Data.Price.Value
local Tool =  game.Lighting.SHOP:FindFirstChild(Search) --Here!
local Player = script.Parent.Parent.Parent.Parent.Parent.Parent

script.Parent.MouseButton1Click:Connect(function()
	if Player.leaderstats.Coin.Value >= Price then
		Player.leaderstats.Coin.Value = Player.leaderstats.Coin.Value - Price
		local Give = Tool:Clone()
		local Give2 = Tool:Clone()
		Give.Parent = Player.StarterGear
		Give2.Parent = Player.Backpack
	end
end)

But it doesnt work at all, and no error on output

2.What You Try To Achive?

I want to make it work so the script can Clone the Tool then insert it to the player backpack and startergear

Thx for Reading!

1 comment

0

You're doing this locally;P buddy you're not actually going to be charging their Coins, it'll remain the same in the Server's perspective; they'll be able to give infinite coins to themselves and trick your LocalScripts for infinite purchases.

2 answers

✓ Accepted answer

Using Lighting as a storage is greatly outdated in terms of common practice. I personally suggest that you use either ReplicatedStorage or ServerStorage for storing the tool to be replicated whenever you want. StarterGear is a service used to replicate tools into players' Backpacks upon spawning. They only replicate them once, as far as I know, and that one time is when they spawn in. If a player's Humanoid dies and the player's Character is respawned, the player will not re-obtain the tool (as far as I know).

Essentially, what you want to set up is a function that will give the player(s) the tool(s) every time their character(s) spawn; StarterGear will not do this for you. You will have to utilize the CharacterAdded event of the player to do this.

3 comments

1

StarterGear replicates tools whenever the character is added.

1

Uhm. No, he's right ^

0

I never use StarterGear so my knowledge of it is faded.

Ey i found the solution!

New Script:

local Data = script.Parent.Parent.CurrentSelection
local Search = Data.ToolName.Value
local Price = Data.Price.Value
local Tool =  game.ServerStorage.SHOP[Search] --New :DD
local Player = script.Parent.Parent.Parent.Parent.Parent.Parent

script.Parent.MouseButton1Click:Connect(function()
    if Player.leaderstats.Coin.Value >= Price then
        Player.leaderstats.Coin.Value = Player.leaderstats.Coin.Value - Price
        local Give = Tool:Clone()
        local Give2 = Tool:Clone()
        Give.Parent = Player.StarterGear
        Give2.Parent = Player.Backpack
    end
end)

Thx to DeceptiveCaster!

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