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

Creating a "Sell Tool" Brick, fails. Why?

Asked by
BryanFehr 133
5 years ago

Hello all, I am creating a Sell Tool system, via bricks, that detect if a tool is in my custom inventory (in the PlayerGui), and if they step on said brick, and the code detectsthat it's in there, it removes it, and gives them their respected amount in Gold for selling their item.

I've done some research, tried a few methods, but cannot seem to nail this one! My inventory is in the PlayerGui and has a model in it that has the items stored inside it. I have tried to connect this LocalScript inside of the brick, and tried with a ServerScript and neither have worked!

Any and all help with this is appreciated! Thank you!

01local player = game.Players.LocalPlayer
02local plrgui = player:WaitForChild("PlayerGui")
03local bp = plrgui.Inventory.Backpack:GetChildren()
04local gold = player.Leaderstats.Gold
05 
06items = "Hero Sword", "Barbarian Sword", "Elvish Warblade", "Master Sword", "Nightcrackle", "Winterviel Staff", "Wooden Sword"
07 
08if player.bp:FindFirstChild("Hero Sword")then
09    gold.Value = gold.Value + 500
10    player.bp:FindFirstChild("Hero Sword"):Destroy()
11end

1 answer

Log in to vote
0
Answered by
Zero_Tsou 175
5 years ago
Edited 5 years ago

So if i didn't get you wrong.. You made a Folder In the Player's Gui Called "Inventory" And Stored The Items in it.... Hmmm

Maybe Try Using a different Methods With Finding the Stored Items By Getting The Player's Character Then Item

... Example:

1local player = game.Players.PlayerAdded:Connect(function(player)
2repeat wait() untill plr.Character
3local char = player.Character

Then

1if char:FindFirstChild("TheItem")then
2gold.Value = gold.Value + 500  
3char:FindFirstChild("TheItem"):Destroy()
4end

Maybe this will Work

And btw Try Doing this in a ServerScript ( Put it in the Workspace )

First thing You Can't do game.players.LocalPlayer in a ServerScript Don't name Your items like this ("Hero Sword") Do it like that ("HeroSword") Maybe this will fix your Issue, If you consider Putting it with Spaces then put it like that ["Hero Sword"]

Example...:

1if char:FindFirstChild["Hero Sword"]
2gold.Value = gold.Valie + 500
3char["Hero Sword"]:Destroy()
0
This never worked, as there's no ontouched function to coexist with the code! I had just seen I had forgotten to add this function. As well, the items in the inventory are stores in the PlayerGui in a model inside the Gui. And when equipped, they're placed as a "tool" in the plr char. BryanFehr 133 — 5y
0
Don't Just copy and paste these Codes, These are just Example, Try Understanding The script and then, Redo it in your own way Zero_Tsou 175 — 5y
0
Ahh. Alright. BryanFehr 133 — 5y
Ad

Answer this question