Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Server Script to local script interaction not working?

Asked by 8 years ago

I seem to be having a strange issue, the first script doesn't seem to be able to cause changed to InfoValue, even though the print statements state otherwise. Also, it seems that during the countdown, the local script can't read the changes. Also, filtering enabled is off when I tested it.

local Players1 = {}
local Sniper = ""
local rs = game:GetService('ReplicatedStorage')
local IntermissionGUI = rs:WaitForChild('InfoValue').Value
local GameInProgress = false

local function RandomSniper()
    local Random = math.random(1,#Players1)

    Sniper = Players1[Random] 
    print("# Of Player1 Array objects: " .. #Players1)
    print("Random Number: "..tostring(Random))
    print("Sniper chosen: " .. tostring(Sniper))

    table.remove(Players1, Random)

end

local function CountDown()
  local Sound = Instance.new("Sound",game.Workspace)

        Sound.SoundId = "http://www.roblox.com/asset/?id=134641113"

    for i = 10,0,-1 do
        print("Countdown: " .. tostring(i))
        IntermissionGUI = tostring("Intermission: " .. i)
          if game.ReplicatedStorage.InfoValue ~= nil then
        print(IntermissionGUI)
        end
    Sound:Play()
        wait(1.5)
    Sound:Stop()
    end
  Sound:Remove()
end

local function PlayerToNumber()
    local Players = game.Players:GetPlayers()

  print("Players being indexed into an array.")

    for i, v in pairs(Players) do
        table.insert(Players1,i,v.Name)

        print(Players1[i])
    end

    return true
end

local function SniperToPosition()

  local Sniper1 = game.Players:FindFirstChild(Sniper)

        Sniper1.TeamColor = BrickColor.new("Really red")

        print("Sniper's Name during the teleportation: "..Sniper1.Name)
    if Sniper1.Character.Torso ~= nil then
        Sniper1.Character.Torso.CFrame = game.Workspace.SpawningPart.CFrame
        print("Sniper Teleport Successful!")
        local Gun = game.ServerStorage.Sniper:Clone()

        Gun.Parent = Sniper1.Backpack

    end
end

local function PlayersToPosition()
    for _, v in pairs(Players1) do
            game.Players:FindFirstChild(v).TeamColor = BrickColor.new("Really blue")
            game.Players:FindFirstChild(v).Character.Torso.CFrame = game.Workspace.PlayerSpawningPart.CFrame
                print("Players being Teleported:" .. v)


    end
end 

local function TouchRestartTheGame(Player)
    print("Game Restarting!")
  local humanoid = Player.Parent:FindFirstChild("Humanoid")

  if humanoid then
    if game.Players:GetPlayerFromCharacter(Player.Parent) then
    print("Character Found!")
    if game.Players:GetPlayerFromCharacter(Player.Parent).TeamColor == BrickColor.new("Really blue") then
        print("Player Team Detected!")
        if humanoid.Health > 0 then 
        if GameInProgress then
    print("Restart Complete!")


                    for _, v in pairs(game.Players:GetChildren()) do
            local character = v.Character

            if character then
                            local torso = character.Torso

              if torso then
                torso.CFrame = game.Workspace.SpawnLocation.CFrame
                v.TeamColor = BrickColor.new("White")
              end
            end 
            end



                        GameInProgress = true

                        CountDown()
                        PlayerToNumber()
                        RandomSniper()
                        SniperToPosition()
                        PlayersToPosition()

                    end 
end
end
      end
    end
end

function RestartTheGame()
    print("Game Restarting!")
    wait(3)
                    for _, v in pairs(game.Players:GetChildren()) do



            local character = v.Character
            local Humanoid = character:WaitForChild("Humanoid")

            if character ~= nil then
                            local torso = character:FindFirstChild("Torso")

              if torso then
                torso.CFrame = game.Workspace.SpawnLocation.CFrame
                v.TeamColor = BrickColor.new("White")
                                end 
                    end
                                  end
                    if game.Players.NumPlayers > 1 then
                        GameInProgress = true

                        CountDown()
                        PlayerToNumber()
                        RandomSniper()
                        SniperToPosition()
                        PlayersToPosition()
            end
            end





game.Players.PlayerRemoving:Connect(function(LeavingPlayer)

    for i,v in pairs(Players1) do
        if v == LeavingPlayer.Name then
            table.remove(Players1, i)
            if #Players1 < 2 then
                for _, v in pairs(game.Players:GetChildren()) do                    
            local character = v.Character
            local Humanoid = character:WaitForChild("Humanoid")

            if character ~= nil then
                            local torso = character:FindFirstChild("Torso")

              if torso then
                torso.CFrame = game.Workspace.SpawnLocation.CFrame
                                end 
                    end
                                  end
                GameInProgress = false
            end
            end
    end
end)


game.Workspace.WinBlock.Touched:connect(TouchRestartTheGame)

game:GetService("Players").PlayerAdded:connect(function(NewPlayer)
        NewPlayer.CharacterAdded:connect(function(Character)
        Character:WaitForChild("Humanoid").Died:connect(function()
            print("Dead Player: " .. NewPlayer.Name)
            if GameInProgress == true then
                if #Players1 > 0 then
                for i,v in pairs(Players1) do
                    if v == NewPlayer.Name then
                        table.remove(Players1,i)
                        if #Players1 < 1 then
                            GameInProgress = false
                            wait(5)
                            IntermissionGUI = tostring(Sniper .. ", the Sniper, has won the game!!!")
                            RestartTheGame()
                            end
                        end
                    end
                    end
            else
                wait(5)
                    IntermissionGUI = tostring(Sniper .. ", the Sniper, has won the game!!!")
                    GameInProgress = false
                    RestartTheGame()
                end
                end)
        end)

    if game.Players.NumPlayers > 1 and GameInProgress == false then
     print("Game In Progress: " ..tostring(GameInProgress))
        GameInProgress = true
     print("Game In Progress: " ..tostring(GameInProgress))
        CountDown()
        PlayerToNumber()
        RandomSniper()
        SniperToPosition()
        PlayersToPosition()
    end


    end)

local ReplicatedStorage = game:GetService('ReplicatedStorage')
local status = ReplicatedStorage:WaitForChild('InfoValue')

script.Parent.Text = status.Value
status.Changed:connect(function()
    print("InfoValue Change!")
script.Parent.Text = status.Value
end)

0
1st script is the server script, second one is the local script. animorphs30 300 — 8y
0
Even if filteringenabled is false, you should use remoteevents/remotefunctions for smooth server to client/client to server communication. shayner32 478 — 8y
0
K, I'll try that out, thanks! animorphs30 300 — 8y

Answer this question