I want to fix my game so that a server script in ServerScriptService can change a value in ReplicatedStorage.
Right now, the problem is that when the round starts, the chicken’s living status doesn’t change. It is a boolean value stored in Replicated Storage.
It turns true when the round starts, and turns false when the chicken is touched, for some reason it is not doing this.
Server Script:
-- Variables --
local intermissionLength = 5
local warningLength = 5
local Players = game:GetService("Players")
local repStorage = game:GetService("ReplicatedStorage")
local inRound = repStorage.InRound
local lobbySpawn = workspace.Spawn
local gameSpawn = workspace.GameSpawn
local Status = repStorage.Status
local chicken = repStorage.Chicken
local chickenStatus = repStorage.Living
inRound.Changed:Connect(function()
if inRound.Value == false then
wait(1)
for _, individualPlayer in ipairs (Players:GetPlayers()) do
individualPlayer.Character.LowerTorso.CFrame = lobbySpawn.CFrame
end
wait(10)
else
for _, player in pairs(game.Players:GetChildren()) do
local newChicken = chicken:Clone()
newChicken.Parent = workspace
player.Character.LowerTorso.CFrame = gameSpawn.CFrame
chickenStatus = true
end
end
end)
local function gametext()
while true do
for i = intermissionLength, 1, -1 do
inRound.Value = false
wait(1)
Status.Value = "Intermission "..i.." seconds left"
end
Status.Value = "Intermission 0 seconds left"
wait(.5)
Status.Value = "Touch the CHICKEN to WIN!"
wait(3)
for i = warningLength, 1, -1 do
wait(1)
Status.Value = "Game Starting in "..i
end
Status.Value = "Game Starting in 0"
wait(.5)
inRound.Value = true
repeat
task.wait()
Status.Value = "Get the CHICKEN!"
until chickenStatus == false
print("yessir")
Status.Value = "The CHICKEN was found!"
wait(.1)
end
end
spawn(gametext)
Chicken Script:
local Players = game:GetService("Players")
local repStorage = game:GetService("ReplicatedStorage")
local chickenStatus = repStorage.Living
local npc = script.Parent
local winner = repStorage.Winner
local db = true
npc.Chicken.MeshPart.Touched:Connect(function(part)
if db == true then
local h = part.Parent:FindFirstChild("Humanoid")
if (h~=nil) then
player = Players:GetPlayerFromCharacter(h.Parent)
if (player~=nil) then
local stats = player:FindFirstChild("leaderstats")
if (stats~=nil) then
local Score = stats:FindFirstChild("Wins")
if (Score~=nil) then
db = false
Score.Value += 1
winner.Value = tostring(player)
local userId = player.UserId
local thumbType = Enum.ThumbnailType.HeadShot
local thumbSize = Enum.ThumbnailSize.Size420x420
local content, isReady = Players:GetUserThumbnailAsync(userId, thumbType, thumbSize)
workspace.WinnerSign.Sign.SurfaceGui.PlayerPicture.Image = content
chickenStatus = false
npc.Humanoid.Health = 0
task.wait(1)
npc:Destroy()
end
end
end
end
end
end)