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

Main Script no longer work due to gamepass script?

Asked by 6 years ago

So I'm currently working on a murder game and in the main script, if you have the gamepass, you will be given a radio upon round start. But here's the problem.(At the top where it says "game.Players.PlayerAdded:connect(function(player)", the word "game" is highlighted in blue, but when I add the radio script, it is no longer highlighted in blue, which means the script will not work. Take a look at it. (CHECK LINE 167 - 214 FOR THE PROBLEM)

local GameStart = game.Workspace.GameStart

game.Players.PlayerAdded:connect(function(player)
    local q = Instance.new("IntValue")
    q.Name = "Queue"
    q.Parent = player
    script.Stats:Clone().Parent = player

    local l = Instance.new("BoolValue")
    l.Name = "leaderstats"
    local lv = Instance.new("IntValue")
    lv.Name = "Level"
    lv.Value = 1
    lv.Parent = l
    local ex = Instance.new("IntValue")
    ex.Name = "Points"
    ex.Value = 0
    ex.Parent = l

    ex.Changed:connect(function()
        if ex.Value>math.floor(10*(1.4^lv.Value)) then
            lv.Value = lv.Value+1
            ex.Value = ex.Value-math.floor(10*(1.4^lv.Value))
        end
    end)

    l.Parent = player
end)

function applyChar(player,char)
    player.PlayerGui.GameGui.Spectate:Remove()
    player.PlayerGui.ShopGUI:Remove()
    for _,e in ipairs(player.Character:GetChildren()) do
        if e.className=="Accessory" or e.className=="Shirt" or e.className=="Pants" or e.className=="CharacterMesh" or e.className=="GraphicShirt" then
            e:Remove()
        end
    end
    for _,e in ipairs(char:GetChildren()) do
        if e.Name=="Head" then
            local h2 = e:Clone()
            h2.Anchored = false
            h2.Name = "Head2"
            player.Character.Head.Transparency = 1
            Instance.new("Weld").Parent = h2
            h2.Weld.Part0 = player.Character.Head
            h2.Weld.Part1 = h2
            h2.Parent = player.Character
            if h2:FindFirstChild("face")~=nil then
                player.Character.Head.face.Texture = h2.face.Texture
                h2.face:Remove()
            end
            player.Character.Torso.BrickColor = h2.BrickColor
            player.Character["Right Arm"].BrickColor = h2.BrickColor
            player.Character["Left Arm"].BrickColor = h2.BrickColor
            player.Character["Right Leg"].BrickColor = h2.BrickColor
            player.Character["Left Leg"].BrickColor = h2.BrickColor
            if char.Name=="Flinn" then
                h2.BrickColor = BrickColor.new("Light orange")
            end
            script.NameGui:Clone().Parent = h2
            h2.NameGui.Display.Text = char.Name
            h2.NameGui.Display.Visible = true
            local nt = Instance.new("StringValue")
            nt.Value = char.Name
            nt.Name = "CharName"
            nt.Parent = player.Character.Humanoid
        elseif e.Name=="Handle" then
            local hat = Instance.new("Hat")
            hat.AttachmentPoint = e.CFrame:inverse()*(char.Head.CFrame*CFrame.new(0,0.5,0))
            e:Clone().Parent = hat
            hat.Handle.FormFactor = "Custom"
            hat.Handle.Size = Vector3.new(0.2,0.2,0.2)
            hat.Handle.Anchored = false
            hat.Parent = player.Character
        else
            e:Clone().Parent = player.Character
        end
    end
    script.OnDeath:Clone().Parent = player.Character
    player.Character.OnDeath.Disabled = false
end

function msgAll(txt)
    for _,p in ipairs(game.Players:GetChildren()) do
        if p:FindFirstChild("PlayerGui")~=nil and p.PlayerGui:FindFirstChild("GameGui")~=nil then
            p.PlayerGui.GameGui.Top.Text = txt
        end
    end
end

function getStatus(player)
    if player.Character~=nil and player.Character:FindFirstChild("Humanoid")~=nil and player.Character.Humanoid.Health>0 then
        return true,player.Character.Humanoid
    else
        return false,nil
    end
end

while true do
    workspace.Map:ClearAllChildren()
wait(5) 

--game.Workspace.Intermission:Play()

    for i=20,1,-1 do
        msgAll("Intermission... "..i)
        wait(1)
    end

local GameInProgress = {
    normal = {
        id = 1,
        name = 'Classic',
        objective = {
            '[A Normal Round Of Murderer]'
        },

    },
    copsandmurderers = {
        id = 2,
        name = 'Sheriffs V.S Murderers',
        objective = {
            '[Sheriffs must kill all murderers]',
            '[Murderers must kill all sheriffs]'
        },

    },
        doubletrouble = {
        id = 3,
        name = 'Double Trouble',
        objective = {
            '[two murderers]',
            '[two sheriffs]'
        },

    },
    doubleagents = {
        id = 4,
        name = 'Double Agents',
        objective = {
            '[one murderer]',
            '[two sheriffs]'
        },

    }
}

    if #(game.Players:GetChildren())<2 then
        msgAll("Waiting for 2 or more players...")
        while #(game.Players:GetChildren())<2 do
            local p = game.Players.PlayerAdded:wait()
            wait(1)
            if p.Character==nil then
                p.CharacterAdded:wait()
            end
        end
    end

    local map = (game.ReplicatedStorage.Maps:GetChildren())[math.random(1,#(game.ReplicatedStorage.Maps:GetChildren()))]:Clone()
    map.Parent = workspace.Map
    --game.Workspace.Intermission:Stop()
    wait(0.1)
    GameStart:Play()
    wait(7.636)
    GameStart:Stop()

    if Game:GetService("GamePassService"):PlayerHasPass(players[i], 314524101) or checkRadio(players[i]) then   -- Radio
                                if players[i].Character ~= nil then
                                    if players[i].Character:findFirstChild("Torso") ~= nil then
                                        local radio = game.ServerStorage.Tools.TwistedRadio:clone()
                                        radio.Parent = players[i].Character
                                        local weld = Instance.new("Weld")
                                        weld.Name = "BackWeld"
                                        weld.Part0 = players[i].Character:findFirstChild("Torso")
                                        weld.Part1 = radio
                                        weld.C0 = CFrame.new(0,0,1)
                                        weld.C0 = weld.C0 * CFrame.fromEulerAnglesXYZ(math.rad(180),math.rad(0), math.rad(180+45))
                                        weld.Parent = radio     
                                        if Game:GetService("GamePassService"):PlayerHasPass(players[i], 314524101) and radio ~= nil then
                                            if radio:findFirstChild("Mesh") ~= nil then
                                            radio.Mesh.MeshId = "http://www.roblox.com/asset/?id=212302951"
                                            radio.Mesh.TextureId = "http://www.roblox.com/asset/?id=212303049"
                                            radio.Mesh.Scale = Vector3.new(4, 4, 5)
                                            end 
                                        end                             
                                    end

                                if Game:GetService("GamePassService"):PlayerHasPass(players[i], 314524101) or checkRadio(players[i]) then   -- Radio

                                        if players[i]:findFirstChild("PlayerGui") ~= nil then
                                            if players[i].PlayerGui:findFirstChild("GUI") ~= nil then
                                                if players[i].PlayerGui.GUI:findFirstChild("TwistedRadioGUI") ~= nil then
                                                players[i].PlayerGui.GUI:findFirstChild("TwistedRadioGUI").Visible = true   
                                                end
                                            end
                                        end                                     
                                else
                                        if players[i]:findFirstChild("PlayerGui") ~= nil then
                                            if players[i].PlayerGui:findFirstChild("GUI") ~= nil then
                                                if players[i].PlayerGui.GUI:findFirstChild("TwistedRadioGUI") ~= nil then
                                                players[i].PlayerGui.GUI:findFirstChild("TwistedRadioGUI").Visible = true
                                                    if players[i].PlayerGui.GUI.TwistedRadioGUI:findFirstChild("BuyRadio") ~= nil then
                                                    players[i].PlayerGui.GUI.TwistedRadioGUI.BuyRadio.Visible = true    
                                                    end

                                                    if players[i].PlayerGui.GUI.TwistedRadioGUI:findFirstChild("Message") ~= nil then
                                                    players[i].PlayerGui.GUI.TwistedRadioGUI.Message.Text = "Earbuds"
                                                    end
                                                end
                                            end
                                        end                                                                 

                        end 
                    end

    local spwn = map.Spawn:GetChildren()

    msgAll("Game in Progress...")
    wait(0.2)

    local p = game.Players:GetChildren()
    local mdrr = 2
    for i=1,#p do
        p[i].Queue.Value = p[i].Queue.Value+1
        if p[i].Queue.Value>p[mdrr].Queue.Value then
            mdrr = i
        end
    end

    local s = {}
    for i=1,#p do if i~=mdrr then s[#s+1] = p[i] end end
    local sherrif = s[math.random(1,#s)]
    local mName = p[mdrr].Name

    local chars = game.ReplicatedStorage.Characters:GetChildren()
    local open = {}
    for i=1, #chars do open[i] = i end  

    for n,player in pairs(p) do
        if player:FindFirstChild("PlayerGui")~=nil and player.PlayerGui:FindFirstChild("GameGui")~=nil then
            local ran = math.random(1,#open)
            applyChar(player,chars[open[ran]])
            if n==mdrr then
                game.ReplicatedStorage.NewRound:FireClient(player,2)
                local tag = Instance.new("BoolValue")
                tag.Name = "Murderer"
                tag.Parent = player.Character.Humanoid
                player.Queue.Value = 0
            elseif p[n]==sherrif then
                game.ReplicatedStorage.NewRound:FireClient(player,1)
                local tag = Instance.new("BoolValue")
                tag.Name = "Cop"
                tag.Parent = player.Character.Humanoid
            else
                game.ReplicatedStorage.NewRound:FireClient(player,0)
            end
            player.Character:MoveTo(spwn[math.random(1,#spwn)].Position)
            table.remove(open,ran)
        end
    end

    local playersAlive = 0
    local murdererAlive = false
    _G.gameMode = nil;
    local timeLeft = 100
    local kills = 0

    for _,p in pairs(game.Players:GetChildren()) do
        if p.Character~=nil and p.Character:FindFirstChild("Humanoid")~=nil then
            p.Character.Humanoid.Died:connect(function()
                kills = kills+1
                timeLeft = timeLeft+20
                if timeLeft>100 then timeLeft=100 end
            end)
        end
    end

    wait(10)

    repeat 
        murdererAlive = false
        playersAlive = 0
        for _,player in ipairs(game.Players:GetChildren()) do
            local isAlive,hum = getStatus(player)
            if isAlive then
                if hum:FindFirstChild("Murderer")~=nil then
                    murdererAlive = true
                elseif hum:FindFirstChild("CharName") then
                    playersAlive =  playersAlive+1
                end
            end
        end
        wait(1)

        timeLeft = timeLeft-1
        game.ReplicatedStorage.TimeUpdate:FireAllClients("Time: "..tostring(timeLeft))
    until playersAlive<=0 or not murdererAlive or timeLeft<=0
    print(murdererAlive,playersAlive)

    local msg,type,cnd

    if murdererAlive and playersAlive>0 then
        msg = "THE MURDERER RAN OUT OF TIME"
        game.Workspace.Both2:Play()     
        cnd = 1
    elseif murdererAlive and playersAlive<=0 then
        msg = "THE MURDERER WINS!"
        game.Workspace.Lost:Play()
        cnd = 2
    elseif not murdererAlive and playersAlive>0 then
        msg = "THE INNOCENT WIN!"
        game.Workspace.Win:Play()
        cnd = 3
    else
        msg = "NOBODY SURVIVED"
        game.Workspace.Both:Play()
        cnd = 4
    end

(Here is the rest of the script starting from "end" which is up by "cnd = 4" https://prnt.sc/izwcsi https://prnt.sc/izwd1f

Answer this question