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

Move Tool from Server Storage to Starter Pack?

So In my game you click on the item button to "buy" it, so it removes the tool from server storage to the starter pack.

It doesn't work though, and my output doesn't give me any errors. Help?

ORIGINAL SCRIPT:

local placeplant = game.ServerStorage:WaitForChild("PlaceBasicPlant")
local price = 0
usestat = "Coins"

function onClicked()
	game.Players.LocalPlayer.leaderstats[usestat].Value = game.Players.LocalPlayer.leaderstats[usestat].Value - 0
	placeplant:Clone()
	placeplant.Parent = game.StarterPack
end

script.Parent.MouseButton1Click:connect(onClicked)

3 answers

There are multiple problems here.

local placeplant = game.ReplicatedStorage:WaitForChild("PlaceBasicPlant") -- Use ReplicatedStorage for this, as this is a local script.
local price = 0
local Player = game.Players.LocalPlayer
local Coins = Player.leaderstats.Coins -- The way you were using this was very inefficient if it even worked. Now, this line has meaning. Also do not forget to put the 'local' in front of it

function onClicked()
	
        Coins.Value =  Coins.Value - 0  -- What is the point of this???? Well whatever.
    	local CLONE = placeplant:Clone() -- Make a variable
    	CLONE.Parent = Player.StarterGear-- Change the cloned item's parent. Also, it needs to be put into the local player's starter gear
end

script.Parent.MouseButton1Click:Connect(onClicked) --Uppercase the Connect for future projects

I just typed this out, typos are bound to have been made. I am simply showing you the flaws of your code, and how to improve it. Reply with any question! Accept the answer if I helped please, have a good day!

2 comments

0

Thank you for the answer, if it works I will accept the answer. Also it is basically buying the item, that is why it takes away money, however it is free so I just put - 0.

0

It sadly did not work. I used the script, I also checked the output. No errors, but it didn't work.

Editing iamnoamesa's script:

local placeplant = game.ReplicatedStorage:WaitForChild("PlaceBasicPlant") -- Use ReplicatedStorage for this, as this is a local script.

local price = 0

local Player = game.Players.LocalPlayer

local Coins = Player.leaderstats.Coins -- The way you were using this was very inefficient if it even worked. Now, this line has meaning. Also do not forget to put the 'local' in front of it

function onClicked()

        Coins.Value = Coins.Value - price -- I figured this would be more universal for future scripts.

        local CLONE = placeplant:Clone() -- Make a variable

        CLONE.Parent = Player.StarterGear -- Change the cloned item's parent. Also, it needs to be put into the local player's starter gear, if it doesn't appear, try resetting.

end

 

script.Parent.MouseButton1Click:Connect(onClicked) -- Uppercase the Connect for future projects

2 comments

0

What did you change in terms of the code?

0

I changed the buying function to Coins.Value = Coins.Value - price instead of typing out the number itself, and spaced out the code making it easier to read

Following up on the other solutions, I think

CLONE.Parent = Player.StarterGear

is supposed to be instead,

CLOSE.Parent - Player.Backpack

Player.Backpack worked for me.

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