Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Move Tool from Server Storage to Starter Pack?

Asked by 7 years ago

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

Log in to vote
0
Answered by 7 years ago

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!

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. Theevilem 23 — 7y
0
It sadly did not work. I used the script, I also checked the output. No errors, but it didn't work. Theevilem 23 — 7y
Ad
Log in to vote
0
Answered by 7 years ago

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

0
What did you change in terms of the code? iamnoamesa 674 — 7y
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 UsernameEqualsTaken 30 — 7y
Log in to vote
0
Answered by 5 years ago

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.

Answer this question