How to make you have the item if the statement is true

so i made a data store script with 2 bool values (i mean i made more values but i just talking about those two rn) so basically one of them called REALKnife and one of the called Stick, and also i made two parts in the workspace one with Knife Image and one with Stick image, and inside of them there’s a clicke detectors

those two parts

so the datastore2 script places inside serverScriptService:

--variables
local DataStore2 = require(game:GetService("ServerScriptService").MainModule)
local mainkey = "eee"
DataStore2.Combine(mainkey, "Stats","SOULS","ITEMS","FOOD","ARMOR")

-- data table
local function SetDataTable()
	local UserData = {
		Stats = {
			["EXP"] = 0,
			["GOLD"] = 0,
			["RESET"] = 0,
			["LOVE"] = 1
			},
		SOULS = {
			["BasicSoul"] = true,
			["Determination"] = false,
			["Integrity"] = false,
			["Justice"] = false,
			["Perseverance"] = false,
			["Kindness"] = false,
			["Bravery"] = false,
			["Patience"] = false,
			["HATE"] = false
		},
		ITEMS = {
			["Stick"] = true,
			["REALKnife"] = false	
		},
		ARMOR = {
			["Bandage"] = true,
			["HeartLocket"] = false	
		},
		FOOD = {
			["MonsterCandy"] = 0,	
		},
	}
	return UserData
end

--main

game.Players.PlayerAdded:Connect(function(plr)
	local UserData = DataStore2(mainkey,plr):Get(SetDataTable())
	
	local gaster = Instance.new("Folder")
	gaster.Name = "TobyFox"
	local soulsfolder = Instance.new("Folder")
	soulsfolder.Name = "SOULS"
	local ITEMS = Instance.new("Folder")
	ITEMS.Name = "ITEMS"
	local ARMOR = Instance.new("Folder")
	ARMOR.Name = "ARMOR"
	local FOOD = Instance.new("Folder")
	FOOD.Name = "FOOD"
	
	--userStats
	local LOVE = Instance.new("IntValue")
	LOVE.Name = "LOVE"
	local GOLD = Instance.new("IntValue")
	GOLD.Name = "GOLD"
	local RESET = Instance.new("IntValue")
	RESET.Name = "RESET"
	local EXP = Instance.new("IntValue")
	EXP.Name = "EXP"
	
	--souls
	local BasicSoul = Instance.new("BoolValue")
	BasicSoul.Name = "BasicSoul"
	local Determination = Instance.new("BoolValue")
	Determination.Name = "Determination"
	local Justice = Instance.new("BoolValue")
	Justice.Name = "Justice"
	local Integrity = Instance.new("BoolValue")
	Integrity.Name = "Integrity"
	local Bravery = Instance.new("BoolValue")
	Bravery.Name = "Bravery"
	local Kindness = Instance.new("BoolValue")
	Kindness.Name = "Kindness"
	local Patience = Instance.new("BoolValue")
	Patience.Name = "Patience"
	local Perseverance = Instance.new("BoolValue")
	Perseverance.Name = "Perseverance"
	local HATE = Instance.new("BoolValue")
	HATE.Name = "HATE"
	--items
	local Stick = Instance.new("BoolValue")
	Stick.Name = "Stick"
	local REALKnife = Instance.new("BoolValue")
	REALKnife.Name = "REALKnife"
	
	--Armor
	local Bandage = Instance.new("BoolValue")
	Bandage.Name = "Bandage"
	local HeartLocket = Instance.new("BoolValue")
	HeartLocket.Name = "HeartLocket"
	
	
	--Food
	local MonsterCandy = Instance.new("IntValue")
	MonsterCandy.Name = "MonsterCandy"
	
	--StoreInFolder
	StatsData = DataStore2("Stats", plr)
	SoulsData = DataStore2("SOULS", plr)
	local ItemsData = DataStore2("ITEMS",plr)
	local FoodData = DataStore2("FOOD", plr)
	local ArmorData = DataStore2("ARMOR", plr)
	
	--Stats data
	local function UpdateStats(UpdateValue) -- updates value to current data
		LOVE.Value = StatsData:Get(UpdateValue).LOVE
		EXP.Value = StatsData:Get(UpdateValue).EXP
		GOLD.Value = StatsData:Get(UpdateValue).GOLD
		RESET.Value = StatsData:Get(UpdateValue).RESET
	end
	
	--Soul data
	local function UpdateSouls(UpdateValue)
		BasicSoul.Value = SoulsData:Get(UpdateValue).BasicSoul
		Determination.Value = SoulsData:Get(UpdateValue).Determination
		Perseverance.Value = SoulsData:Get(UpdateValue).Perseverance
		Patience.Value = SoulsData:Get(UpdateValue).Patience
		Kindness.Value = SoulsData:Get(UpdateValue).Kindness
		Bravery.Value = SoulsData:Get(UpdateValue).Bravery
		Justice.Value = SoulsData:Get(UpdateValue).Justice
		Integrity.Value = SoulsData:Get(UpdateValue).Integrity
		HATE.Value = SoulsData:Get(UpdateValue).HATE
	end
	
	--items Data
	local function UpdateITEM(UpdateValue)
		Stick.Value = SoulsData:Get(UpdateValue).Stick
		REALKnife.Value = SoulsData:Get(UpdateValue).REALKnife
	end
	
	--update data
	UpdateStats(UserData.Stats)
	UpdateSouls(UserData.SOULS)
	UpdateITEM(UserData.ITEMS)
	
	StatsData:OnUpdate(UpdateStats)
	SoulsData:OnUpdate(UpdateSouls)
	ItemsData:OnUpdate(UpdateITEM)

	
	
	--parent
	gaster.Parent = plr
	soulsfolder.Parent = plr
	ITEMS.Parent = plr
	--allinonestats
	--stats
	LOVE.Parent = gaster
	RESET.Parent = gaster
	EXP.Parent = gaster
	GOLD.Parent = gaster
	--Souls
	Determination.Parent = soulsfolder
	BasicSoul.Parent = soulsfolder
	Perseverance.Parent = soulsfolder
	Integrity.Parent = soulsfolder
	Justice.Parent = soulsfolder
	Kindness.Parent = soulsfolder
	Bravery.Parent = soulsfolder
	Patience.Parent = soulsfolder
	HATE.Parent = soulsfolder
	--ITENS
	REALKnife.Parent = ITEMS
	Stick.Parent = ITEMS
	
		--LEVE SYSTEN start
EXP.Changed:connect(function()
	if UserData.Stats.LOVE < 100 then
		if UserData.Stats.EXP >= UserData.Stats.LOVE*25 + 10 then
			UserData.Stats.EXP = UserData.Stats.EXP - (UserData.Stats.LOVE*25 + 10)
			UserData.Stats.LOVE = UserData.Stats.LOVE + 1
			StatsData:Set(UserData.Stats)
		end
	end
end)
end)

basically i made a script that changes the stick bool value to false and Realknife value to true if you click the part with the knife picture, and the stick to true and Realknife to false if you click the part with the stick picture

the script:

workspace.Chooseitem.Knife.ClickDetector.MouseClick:Connect(function(plr)
local itemdata = DataStore2("ITEMS", plr)
local UserData = DataStore2(mainkey,plr):Get(SetDataTable())
local Stick = UserData.ITEMS.Stick
local REALKnife = UserData.ITEMS.REALKnife

if REALKnife == true then
UserData.ITEMS["REALKnife"] = false
UserData.ITEMS["Stick"] = true
itemdata:Set(UserData.ITEMS)
Stick = true
REALKnife = false
elseif REALKnife == false then
UserData.ITEMS["REALKnife"] = true
UserData.ITEMS["Stick"] = false
itemdata:Set(UserData.ITEMS)
REALKnife = true
Stick = false
end
plr:LoadCharacter()
end)

workspace.Chooseitem.Stick.ClickDetector.MouseClick:Connect(function(plr)
local itemdata = DataStore2("ITEMS", plr)
local UserData = DataStore2(mainkey,plr):Get(SetDataTable())
local Stick = UserData.ITEMS.Stick
local REALKnife = UserData.ITEMS.REALKnife


if Stick == true then
UserData.ITEMS["Stick"] = true
itemdata:Set(UserData.ITEMS)
Stick = true
elseif Stick == false then
UserData.ITEMS["REALKnife"] = false
UserData.ITEMS["Stick"] = true
itemdata:Set(UserData.ITEMS)
REALKnife = false
Stick = true
end
plr:LoadCharacter()
end)

also, i made two tools placed inside StarterPack, one is knife and one stick, so all i want to do is to make a if statement, that says:

if REALKnife.Value == true then
the weapon will be in the backpack
elseif false
the weapon won’t be inside backpack
end

same with the stick…

hope this post was understandable , thanks in advance :slight_smile:

ok since you want to do a if statement, i recommened doing it like this;
Note: using else just means if RealKnife does not equal whatever you want it to equal in the if statement

if RealKnife.Value == true then
--Code for putting tool in backpack.
else
      -- Dont Do anything unless needed.
      print('RealKnife was Not Inserted into the players backpack')
end

wdym “since you want to do a if statement”, is there another way to do this without if statement… and also i don’t know where to put the tools? and where to place this script

Unfortunately, at the moment, you could only use a if statement in this case.
EDIT: What do you mean where to place this script?

To give a tool to a player, you need to Clone the item and give it to the players backpack.

so the script suppose to be inside the tool, but where the tool suppose to be?

Are you doing this by a Gui Button? How would you like to give a tool to a player?

yea , in the future i want to do a gui button, but for now i’m using a part with click detector, if you click the part then the boolvalue of the item you clicked will be true (Knife,Stick), like i mentioned in the post

do you want the item bool value to be set to true once its clicked?

i already did it, but i to make that if the bool value is true then you will have the item in the backpack, else if it false then you will not have the item

Ok for a ClickDetector, it would go like this.
(this is if you want the script in the part)

    -- Put Everything else above this (this is for a Script) -- 

    local ClonedRealKnife = RealKnife:Clone()

    script.parent.ClickDetector.MouseClick:Connect(function(plr)
    if REALKNIFE == true  then
    if ClonedRealKnife.Parent ~= plr.Backpack then
       ClonedRealKnife.Parent = plr.Backpack
   else
        end
    end)

it didn’t worked, i changed my mind , i’ll create this gui now so brb

1 Like

Did it work or did you make the gui? If it did, select my answer and make it as a Solution

i’m still making the gui, it will take sometime to finish it