I’m currently making a game that has different modes, and there’s a StringValue that holds the game mode’s name. It is changed by one script so another script knows which weapons are appropriate for the chosen mode.
Strangely, the StringValue change isn’t replicated across the game, and seems to be confined to the script itself. Every other script runs as if the StringValue never changed. Unfortunately, no errors appear in the output.
This is the GameControl code that’s supposed to change the StringValue’s value:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("ChangeTopText")
local timerRemote = ReplicatedStorage:WaitForChild("TimerRemote")
local CurrentMode = game.Workspace.CurrentMode.Value
wait(5)
while true do
-- Start
remoteEvent:FireAllClients("Starting a new round...")
wait(3)
remoteEvent:FireAllClients("This round's game mode will be...")
wait(2)
-- Pick the mode
local Mode = math.random(1,6)
if Mode == 1 then
remoteEvent:FireAllClients("Shotguns!")
CurrentMode = "Shotguns"
game.Workspace.ModeString.Value = "Shotguns"
end
if Mode == 2 then
remoteEvent:FireAllClients("Heavy Weapons!")
CurrentMode = "Heavy Weapons"
game.Workspace.ModeString.Value = "Heavy Weapons"
end
if Mode == 3 then
remoteEvent:FireAllClients("Snipers!")
CurrentMode = "Snipers"
game.Workspace.ModeString.Value = "Snipers"
end
if Mode == 4 then
remoteEvent:FireAllClients("Rifles!")
CurrentMode = "Rifles"
game.Workspace.ModeString.Value = "Rifles"
end
if Mode == 5 then
remoteEvent:FireAllClients("Submachine Guns!")
CurrentMode = "Submachine Guns"
game.Workspace.ModeString.Value = "Submachine Guns"
end
if Mode == 6 then
remoteEvent:FireAllClients("Handguns!")
CurrentMode = "Handguns"
game.Workspace.ModeString.Value = "Handguns"
end
print(game.Workspace.ModeString.Value .. " has been chosen")
wait(3)
-- 10% chance to have a twist
local Twist = math.random(1,10)
if Twist == 10 then
remoteEvent:FireAllClients("But wait, there's a twist!")
wait(2.5)
-- Pick the twist
local TwistMode = math.random(1,4)
if TwistMode == 1 then
remoteEvent:FireAllClients("Explosions: Players explode when they die")
end
if TwistMode == 2 then
remoteEvent:FireAllClients("Easy Mode: Speed, jump, and chair health increased")
end
if TwistMode == 3 then
remoteEvent:FireAllClients("Zombies: Zombie NPCs will appear")
end
if TwistMode == 4 then
remoteEvent:FireAllClients("Bomb Rain: Bombs will drop onto the map")
end
wait(4)
end
remoteEvent:FireAllClients("Starting the round...")
-- Respawn all players
for i, player in ipairs(game.Players:GetPlayers()) do
if player.Character then
local hum = player.Character:FindFirstChild('Humanoid')
if hum then
hum.Health = 0
end
end
end
wait(1)
-- Round start
remoteEvent:FireAllClients("Fight for the chair!")
wait(3)
remoteEvent:FireAllClients("Current Mode: " .. game.Workspace.ModeString.Value)
timerRemote:FireAllClients("2:00")
for minute = 1,0,-1 do
for second = 59,0,-1 do
wait(1)
timerRemote:FireAllClients(minute .. ":" .. second)
end
end
wait(1)
-- Round end
remoteEvent:FireAllClients("Time's up!")
CurrentMode = "..."
wait(2)
for i, player in ipairs(game.Players:GetPlayers()) do
if player.Character then
local hum = player.Character:FindFirstChild('Humanoid')
if hum then
hum.Health = 0
end
end
end
wait(1)
end
And this is the code for the WeaponGiver script that gives weapons:
local Storage = game:GetService("ReplicatedStorage")
local Gamemode = game.Workspace.CurrentMode.Value
local SS = game:GetService("ServerStorage")
local WeaponFolder = SS.Weapons
game.Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(character)
print("Giving weapon...")
wait(0.5)
if Gamemode == "Shotguns" then
local Weapons = WeaponFolder.Shotguns:GetChildren()
local randomWeapon = Weapons[math.random(1, #Weapons)]
print("Shotgun was given")
local Tool = randomWeapon:Clone()
Tool.Parent = Player.Backpack
end
if Gamemode == "Heavy Weapons" then
local Weapons = WeaponFolder.Heavy:GetChildren()
local randomWeapon = Weapons[math.random(1, #Weapons)]
print("Heavy weapon was given")
local Tool = randomWeapon:Clone()
Tool.Parent = Player.Backpack
end
if Gamemode == "Snipers" then
local Weapons = WeaponFolder.Snipers:GetChildren()
local randomWeapon = Weapons[math.random(1, #Weapons)]
print("Snpier was given")
local Tool = randomWeapon:Clone()
Tool.Parent = Player.Backpack
end
if Gamemode == "Rifles" then
local Weapons = WeaponFolder.Rifles:GetChildren()
local randomWeapon = Weapons[math.random(1, #Weapons)]
print("Rifle was given")
local Tool = randomWeapon:Clone()
Tool.Parent = Player.Backpack
end
if Gamemode == "Submachine Guns" then
local Weapons = WeaponFolder.SMGs:GetChildren()
local randomWeapon = Weapons[math.random(1, #Weapons)]
print("SMG was given")
local Tool = randomWeapon:Clone()
Tool.Parent = Player.Backpack
end
if Gamemode == "Handguns" then
local Weapons = WeaponFolder.Handguns:GetChildren()
local randomWeapon = Weapons[math.random(1, #Weapons)]
print("Handgun was given")
local Tool = randomWeapon:Clone()
Tool.Parent = Player.Backpack
end
if Gamemode == "..." then
print("Mode isn't chosen")
end
print("Weapon given!")
end)
end)
I even decided to make a separate detector script that uses the Changed function:
game.Workspace.CurrentMode.Changed:Connect(function()
print("The CurrentMode StringValue changed.")
end)
And whenever a player spawns during a round, the WeaponGiver only runs the code as if the string was “…” and not any of the game modes, therefore does not give any weapons. Furthermore, the detector script is also not ran when the GameControl script changes the StringValue.Value. And strangely enough, when I tested it in studio, both the Client and the Server saw the StringValue as “…” and not a mode. It seems that the StringValue change is confined to the GameControl script.
(I want it to be known that all 3 scripts are in fact Scripts and not LocalScripts, and that they are all in the ServerScriptService)