How would i make an Equip and Unequip system with the data also being sent to the game level (any level ex: level 1 )

Should i give you more context on the game and let you playtest it? or do you not need that

Yes that would help. Also are you teleporting the player to a private server or a another place?

I am teleporting them to another place thats part of the game in asset manager as seen here, the game levels are also private
image

Heres the game - https://www.roblox.com/games/7857783877/Jeffersun-WIP

You just need to make sure you put the datstore script in BOTH places, and RemoteEvents too.

So would i do that for every level and then go from there with the rest?

Yeah for every level, the preformance should be fine. Since you’re reseting the data everytime it has been used.

1 Like

For the first script, what is it doing?

The first 4 scripts are using TeleportData, I recommend you use the Datastore one - The last one there.

I also edited the datastore script

I forgot to do the local part for that

--LOCAL SCRIPT IN THE MAIN GAME
local player = game.Players.LocalPlayer
local M4A1 = player.M4A1
local M82 = player.M82
local Vector = player.Vector
local Button = script.Parent.Button -- Whatever the directory
local PlayButton = script.Parent.PlayButton
local TeleportService = game:GetService("TeleportService")

-- Here is an example of changing the value
Button.MouseButton1Click:Connect(function()
if M4A1.Value = "Suppressed" then
M4A1.Value = "Normal"
Button.Text = "M4A1 Supressed"
else
M4A1.Value = "Suprresed"
Button.Text = "M4A1"
end
end)

--Firing to the server
PlayButton.MouseButton1Click:Connect(function()
game.ReplicatedStorage.Event:FireServer()
wait(5)
TeleportService:TeleportAsync(Put the teleportId here, player)
end)

Now in the Level

--LOCAL SCRIPT IN THE LEVEL
local player = game.Players.LocalPlayer

if player.M4A1.Value == "Suppressed" then
--give the suppressed weapon
else
--give the other weapon
end
1 Like

Where do i put the local script in the main game?

You can put it in your menu, or anything like that.

Local script in level can go into startergui

Let me explain whats going on inside the game,
Theres a Button to Equip the Suppressors and another to Equip in the Galaxy Skin one
When you click equip, it now says “Equipped” instead of “Equip” which you can also click to unequip it
If an attachment is equipped, the bool value that acts as a true or false for if its selected or not is inside of a script in StarterPlayerScripts


when you press Confirm it fires to a server script that prints to make sure it works, then it fires to
the script that checks all the different combinations of the bool value, when it doesnt get the combination it prints and if it gets one of the 4 correct then it fires to a server script that will then fire to the local script that changes everything
which is the script from earlier but edited because someone told me to organize it

local Copy1 = game.ReplicatedStorage.WeaponCustomizations["M4A1 Suppressed Galaxy"]
local Copy2 = game.ReplicatedStorage.WeaponCustomizations["M4A1 Galaxy"]
local Copy3 = game.ReplicatedStorage.WeaponCustomizations["M4A1 Suppressed"]

local Copy4 = game.ReplicatedStorage.WeaponCustomizations["M82 Suppressed Galaxy"]
local Copy5 = game.ReplicatedStorage.WeaponCustomizations["M82 Galaxy"]
local Copy6 = game.ReplicatedStorage.WeaponCustomizations["M82 Suppressed"]

local Copy7 = game.ReplicatedStorage.WeaponCustomizations["Vector Suppressed Galaxy"]
local Copy8 = game.ReplicatedStorage.WeaponCustomizations["Vector Galaxy"]
local Copy9 = game.ReplicatedStorage.WeaponCustomizations["Vector Suppressed"]
wait(1)
local playergui = game.Players.LocalPlayer.PlayerGui.MainMenuGUI.MainMenu.SkinsAndGearFrame.MainViewportFrame
local viewport = playergui
local ReplicatedStorage = game.ReplicatedStorage.WeaponCustomizations

game.ReplicatedStorage.ChangeWeaponSuppressedGalaxy.OnClientEvent:Connect(function(Player)
	print("Attempt 1")

	for _, v in pairs(viewport.GunFolder:GetChildren()) do
		v.Parent = ReplicatedStorage
	end
	Copy1.Parent = viewport.GunFolder
	Copy4.Parent = viewport.GunFolder
	Copy7.Parent = viewport.GunFolder
	
	
	
	print("Changed To Suppressed Galaxy")

end)

game.ReplicatedStorage.ChangeWeaponSuppressed.OnClientEvent:Connect(function(Player)
	print("Attempt 2")
	for _, v in pairs(viewport.GunFolder:GetChildren()) do
		v.Parent = ReplicatedStorage
	end
	
	Copy3.Parent = viewport.GunFolder
	Copy6.Parent = viewport.GunFolder
	Copy9.Parent = viewport.GunFolder
	
	
	
	print("Changed To Suppressed")
end)

wait()
game.ReplicatedStorage.ChangeWeaponGalaxy.OnClientEvent:Connect(function(Player)
	print("Attempt 3")
	for _, v in pairs(viewport.GunFolder:GetChildren()) do
		v.Parent = ReplicatedStorage
	end
	Copy2.Parent = viewport.GunFolder
	Copy5.Parent = viewport.GunFolder
	Copy8.Parent = viewport.GunFolder
	
	
	
	print("Changed To Galaxy")
end)

Sorry if everything is made incorrectly or not made correctly, even though it all works. I’m usually just good in gui stuff when it comes to scripting

Heres also what it looks like in explorer
image

Would i only need the value for one of the guns (lets just say the M4A1 for simplicity) and then send that data to all the levels if i use that data to set everything else to “Suppressed”?

You could make a function to do all that

Oh ok so i would use a function to set all the guns to that specific setting?

Yes a function should work fine.

local function SuppressAllGuns()
M4A1.Value = "Suppressed"
M82.Value = "Suppressed"
Vector.Value = "Suppressed"
end
1 Like

thanks for all the help, ill try and figure out a way to connect everything with what i have. ill be back if i need some more help

Where do i put the local script in the level?
in the level the player spawns in with the tools.
But if im supposed to change it then what do i do? I modified the script to this

game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(character)
	
local player = game.Players.LocalPlayer
		
		if player.M4A1.Value == "Suppressed" then
			player.Backpack:ClearAllChildren()
			game.ReplicatedStorage.Guns["M4A1 Suppressed"].Parent = player.Backpack
		else
			player.Backpack:ClearAllChildren()
			game.ReplicatedStorage.Guns["M4A1 Suppressed"].Parent = player.Backpack
		end
	end)
end)

I would recommend it be put in startergui. If you want to change the value in the level you could do this

player.M4A1.Value = "Normal" -- just changing the value
player.M4A1:GetPropertyChangedSignal("Value"):Connect(function() -- Everytime the valu
if player.M4A1.Value == "Normal" then -- If the value was changed to normal
local Suppressed = player.Backpack:FindFirstChild("M4A1 Suppressed") -- Looks for the suppressed weapon
if Suppressed then -- If the suppressed weapon is there
Suppressed:Destroy() -- Destroys the suppressed weapon
end
game.ReplicatedStorage.Guns.M4A1.Parent = player.Backpack -- Gives the normal weapon

elseif player.M4A1.Value == "Suppressed" then -- If the value was changed to suppressed
local Normal = player.Backpack:FindFirstChild("M4A1") -- Looks for the normal weapon
if Normal then -- If the suppressed weapon is there
Normal:Destroy() -- Destroys the suppressed weapon
end
game.ReplicatedStorage.Guns["M4A1 Suppressed"].Parent = player.Backpack -- Gives the normal weapon
end)

Thats only if you want to change the weapon in the level.

Try this instead, it will give the player a suppressed weapon if the value is suppressed and if it isn’t it gives them the normal one.

game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(character)
		if Player.M4A1.Value == "Suppressed" then
			game.ReplicatedStorage.Guns["M4A1 Suppressed"].Parent = player.Backpack
		else
			game.ReplicatedStorage.Guns.M4A1.Parent = player.Backpack
		end
	end)
end)
1 Like

I changed some stuff about the Datastore scripts so it would work simpler, but I dont know if its supposed to work
heres an error the output gave
image
SendData is the server script

--Server script in the main game
local DataStoreService = game:GetService("DataStoreService")
local GunStore = DataStoreService:GetDataStore("SceneStore")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Delete = ReplicatedStorage.Sent

--Making the values
game.Players.PlayerAdded:Connect(function(Player)
	local GunDataFolder = Instance.new("Folder", Player)
	GunDataFolder.Name = "GunDataFolder"
	local Guns = Instance.new("StringValue", GunDataFolder)
	Guns.Name = "GunsValue"

	local GetData =  GunStore:GetAsync(Player.UserId)

	if GetData ~= nil then
		Guns.Value = GetData[1]
	else
		Guns.Value = ""
	end
end)


--Saving the data 
game.ReplicatedStorage.SendSuppressed.OnServerEvent:Connect(function(Player)
	local SaveData =  {}
	for _,Child in pairs(Player.GunDataFolder:GetChildren())do
		table.insert(SaveData,Child.Value)
	end
	GunStore:SetAsync(Player.UserId, SaveData)
	print("Sent")
end)

--Deleting it forever until its set again
Delete.OnServerEvent:Connect(function(Player)
	GunStore:RemoveAsync(Player.UserId)
	print("Deleted")
end)
--LOCAL SCRIPT IN THE MAIN GAME
local player = game.Players.LocalPlayer
local Suppressed = game.Players.LocalPlayer.PlayerScripts.ImageSetter.SuppressedImage
local Guns = player.GunsDataFolder.Guns
local Button = script.Parent.Parent.Parent.SkinsAndGearFrame.EquipFrame.Confirmbutton
local PlayButton = script.Parent.Parent["Level 1"]
local TeleportService = game:GetService("TeleportService")

-- Here is an example of changing the value
Button.MouseButton1Click:Connect(function()
	wait(2)
	if Guns.Value == 1 then
		Guns.Value = "Suppressed"
		Button.Text = "Supressed"
	else
		Suppressed.Value = "Default"
		Button.Text = "Default"
	end
end)

--Firing to the server
PlayButton.MouseButton1Click:Connect(function()
	game.ReplicatedStorage.Sent:FireServer()
	wait(5)
	TeleportService:TeleportAsync(8191295398, player)
end)
-- script in the level
game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(character)
		local player = game.Players.LocalPlayer
		if Player.M4A1.Value == "Suppressed" then
			game.ReplicatedStorage.Guns["M4A1 Suppressed"].Parent = player.Backpack
		else
			game.ReplicatedStorage.Guns.M4A1.Parent = player.Backpack
		end
	end)
end)

The Guns.Value thing doesn’t make sense, It wouldn’t work like that. I made a new datastore script

New Datastore

--Variables
local DataStoreService = game:GetService("DataStoreService")
local GunStore = DataStoreService:GetDataStore("GunStore")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Event = ReplicatedStorage.Event
local Delete = ReplicatedStorage.Delete

game.Players.PlayerAdded:Connect(function(player)
    local GunDataFolder = Instance.new("Folder",player)
   GunDataFolder.Name = "GunDataFolder" 

local M4A1 = Instance.new("StringValue", GunDataFolder)
	M4A1.Name = "M4A1"

	local M82 = Instance.new("StringValue", GunDataFolder)
	M82.Name = "M82"

	local Vector = Instance.new("StringValue", GunDataFolder)
	Vector.Name = "Vector"

    local data
    local success, err = pcall(function()
        data = GunStore:GetAsync(player.UserId)
    end)

    if success then
        M4A1.Value = data
        M82.Value = data
Vector.Value = data
    end
end)

Event.OnServerEvent:Connect(function(player)
    local success, err = pcall(function()
        GunStore:SetAsync(player.UserId,{player.M4A1.Value, player.M82.Value, player.Vector.Value})
    end)

    if success then
        print("Success")
    else
        warn(err)
    end
end)

Delete.OnServerEvent:Connect(function(Player)
	GunStore:RemoveAsync(Player.UserId)
end)

Local Script Main game

--LOCAL SCRIPT IN THE MAIN GAME
local player = game.Players.LocalPlayer
local M4A1 = player.M4A1
local M82 = player.M82
local Vector = player.Vector
local Button = script.Parent.Button -- Whatever the directory
local ButtonOther = script.Parent.ButtonOther -- Whatever the directory
local PlayButton = script.Parent.PlayButton
local TeleportService = game:GetService("TeleportService")

local function SuppressAllGuns()
M4A1.Value = "Suppressed"
M82.Value = "Suppressed"
Vector.Value = "Suppressed"
end

local function RemoveAllAttachments()
M4A1.Value = "Normal"
M82.Value = "Normal"
Vector.Value = "Normal"
end


-- Here is an example of changing the value
Button.MouseButton1Click:Connect(function()
if M4A1.Value == "Suppressed" then
M4A1.Value = "Normal"
Button.Text = "M4A1 Supressed"
else
M4A1.Value = "Suprresed"
Button.Text = "M4A1"
end
end)

--Alternatively to make a button that makes all guns suppressed
Button.MouseButton1Click:Connect(function()
SuppressAllGuns()
end)
--One that removes all
ButtonOther.MouseButton1Click:Connect(function()
RemoveAllAttachments()
end)
--Firing to the server
PlayButton.MouseButton1Click:Connect(function()
game.ReplicatedStorage.Event:FireServer()
wait(5)
TeleportService:Teleport(Put the teleportId here, player)
end)

And local script in the level

-- script in the level
game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(character)
		local player = game.Players.LocalPlayer
		if Player.M4A1.Value == "Suppressed" then
			game.ReplicatedStorage.Guns["M4A1 Suppressed"].Parent = player.Backpack
		else
			game.ReplicatedStorage.Guns.M4A1.Parent = player.Backpack
		end
         if Player.M82.Value == "Suppressed" then
			game.ReplicatedStorage.Guns["M82 Suppressed"].Parent = player.Backpack
		else
			game.ReplicatedStorage.Guns.M82.Parent = player.Backpack
		end

if Player.M4A1.Value == "Suppressed" then
			game.ReplicatedStorage.Guns["Vector Suppressed"].Parent = player.Backpack
		else
			game.ReplicatedStorage.Guns.Vector.Parent = player.Backpack
		end
	end)
end)

I hope this helps, once again tell me if they’re any other issues. If not make sure to mark this as a soloution so that people know it has been solved.