I’m having a hard time understand your script but I’ve made a system that should work.
--Server Script IN THE LOBBY - aka the place that teleports you to the other.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Event = ReplicatedStorage.Event -- Put your event directory here
local teleportOptions = Instance.new("TeleportOptions")
local Player = game:GetService("Players")
Player.PlayerAdded:Connect(function(Player)
local M4A1 = Instance.new("StringValue", Player)
M4A1.Name = "M4A1"
M4A1.Value = "Normal"
local M82 = Instance.new("StringValue", Player)
M82.Name = "M82"
M82.Value = "Normal"
local Vector = Instance.new("StringValue", Player)
Vector.Name = "Vector"
Vector.Value = "Normal"
end)
Event.OnServerEvent:Connect(function(player)
GunData = {
M4A1 = player.M4A1.Value
M82 = player.M82.Value
Vector = player.Vector.Value
}
teleportOptions:SetTeleportData(GunData)
TeleportService:TeleportAsync(Put the teleportId here, {player}, teleportOptions)
end)
-- local script IN THE LOBBY - aka the place that teleports you to the other.
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
-- 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()
end)
--local script in the new place
local TeleportService = game:GetService("TeleportService")
local player = game.Players.LocalPlayer
local GunData = TeleportService:GetLocalPlayerTeleportData()
if GunData then
player.M4A1.Value = GunData.M4A1
player.M82.Value = GunData.M82
player.Vector.Value = GunData.Vector
end)
--Server Script In new place
local Player = game:GetService("Players")
Player.PlayerAdded:Connect(function(Player)
local M4A1 = Instance.new("StringValue", Player)
M4A1.Name = "M4A1"
local M82 = Instance.new("StringValue", Player)
M82.Name = "M82"
local Vector = Instance.new("StringValue", Player)
Vector.Name = "Vector"
end)
As @Messeras has said this system may not be the best way.
This system could also work with datastore.
--Server
--Variables
local DataStoreService = game:GetService("DataStoreService")
local GunStore = DataStoreService:GetDataStore("SceneStore")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Event = ReplicatedStorage.Event
local Delete = ReplicatedStorage.Delete
--Making the values
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 GetData = GunStore:GetAsync(Player.UserId)
if GetData ~= nil then
M4A1.Value = GetData[1]
M82.Value = GetData[2]
Vector.Value = GetData[3]
else
M4A1.Value = ""
M82.Value = ""
Vector.Value = ""
end
end)
--Saving the data
Event.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)
end)
--Deleting it forever until its set again
Delete.OnServerEvent:Connect(function(Player)
GunStore:RemoveAsync(Player.UserID)
end)
I hope this helps, tell me if anything is wrong.
Also my bad I forgot to mention that the datastore will only work in these situations.
- The other place is under the same game
- You make a private Server
The scripts that say “In the new place” can be placed in the same place as long as you use private servers. If not then put it in the other place.
If you are teleporting to another place, make sure to make the events in that place aswell.