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

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

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!

local player = game.Players.LocalPlayer
local plrgui = player:WaitForChild("PlayerGui")
local bp = plrgui.Inventory.Backpack:GetChildren()
local gold = player.Leaderstats.Gold

items = "Hero Sword", "Barbarian Sword", "Elvish Warblade", "Master Sword", "Nightcrackle", "Winterviel Staff", "Wooden Sword"

if player.bp:FindFirstChild("Hero Sword")then
	gold.Value = gold.Value + 500
	player.bp:FindFirstChild("Hero Sword"):Destroy()
end

1 answer

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:

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

Then

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

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...:


if char:FindFirstChild["Hero Sword"]
gold.Value = gold.Valie + 500
char["Hero Sword"]:Destroy()

3 comments

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.

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

0

Ahh. Alright.

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