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)
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!
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
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.