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

Roblox Scripting | display gui when inround true doesnt work! Help?

Asked by 4 years ago

So, im making an murder mystery game, and the thing that appears on start of the round is the "show my role" gui or "show me if im murderer or innocent or sheriff" gui, and i first tried to do it in the script in the serverscriptservice because thats where my main stuff about rounds and intermission timing and stuff is located, but that didnt work, the next thing i tried was to do it with the boolvalue (i had 2 of them in my script, one for saying when the round starts and ends, and one that says to display the "show my role" gui), and that didnt work either, so a few minutes before, i tried to do it with the inround value(which in fact did work) but then the text stopped to change, and after that it just breaks, and shows the gui when the player is in lobby, and hides it when the player is in round.

My code is (Main Script):

local roundLength = 5
local intermissionLength = 5
local status = game.ReplicatedStorage.IntermissionStatus
local inround = game.ReplicatedStorage.InRound
local chosenRandomNumberValue = game.ReplicatedStorage.chosenNumber
local displaychosenrole = game.StarterGui.areyoumurdorsherifforinno.Chosen.TextLabel
local tof = game.ReplicatedStorage.displayChosenTOF
local player = game.Players.LocalPlayer
local chosenRoleValue = game.ReplicatedStorage.TheChosenRole

local murdererteam = game.Teams.Murderer
local sheriffteam = game.Teams.Sheriff
local innocentteam = game.Teams.Innocent

local mineshaft = game.Workspace.MineshaftSpawn
local milbase = game.Workspace.MilbaseSpawn
local lobby = game.Workspace.LobbySpawn

local colorRed = Color3.new(255/255, 0/255, 4/255)
local colorBlue = Color3.new(16/255, 40/255, 255/255)
local colorGreen = Color3.new(3/255, 255/255, 19/255)

inround.Changed:Connect(function()
    if inround.Value == true then   

        for _, player in pairs(game.Players:GetChildren()) do

            local char = player.Character
            local randomMapNumber = math.random(1,2)
            if randomMapNumber == 1 then

                char.HumanoidRootPart.CFrame = mineshaft.CFrame
            elseif randomMapNumber == 2 then

                char.HumanoidRootPart.CFrame = milbase.CFrame
            end

            local randomNumber = math.random(1,3)
            if randomNumber == 1 then

                player.TeamColor = BrickColor.new("Really red")
                chosenRoleValue.Value = "MURDERER"
            elseif randomNumber == 2 then

                player.TeamColor = BrickColor.new("Electric blue")
                chosenRoleValue.Value = "SHERIFF"
            elseif randomNumber == 3 then

                player.TeamColor = BrickColor.new("Lime green")
                chosenRoleValue.Value = "INNOCENT"
            end

        end
    else
        for _,player in pairs(game.Players:GetChildren()) do
            local char = player.Character
            char.HumanoidRootPart.CFrame = lobby.CFrame     
            player.TeamColor = BrickColor.new("White")
            chosenRoleValue.Value = "NEUTRAL"
        end
    end

end)



local function roundTimer()

    while wait() do
        for i = intermissionLength, 1, -1 do
            inround.Value = false
            wait(1)
            status.Value = "Intermission: ".. i .." seconds left!"
            wait(1)

        end
    for i = roundLength, 1, -1 do
            inround.Value = true
            wait(1)

            status.Value = "Game: ".. i .." seconds left!"

        end

    end

end

spawn(roundTimer)

My code for the gui script:

local chosenNumber = game.ReplicatedStorage.chosenNumber
local status = script.Parent.TextLabel
local tof = game.ReplicatedStorage.displayChosenTOF
local chosenRole = game.ReplicatedStorage.TheChosenRole
local inround = game.ReplicatedStorage.InRound



chosenRole.Changed:Connect(function()

    if chosenRole.Value == "MURDERER" then
        status.TextColor3 = Color3.new(255/255, 0/255, 4/255)
        status.Text = "MURDERER"
        if inround.Value == true then
            script.Parent.Parent.Chosen.Visible = true
            wait(5)
            script.Parent.Parent.Chosen.Visible = false
        end
    elseif chosenRole.Value == "SHERIFF" then
        status.TextColor3 = Color3.new(16/255, 40/255, 255/255)
        status.Text = "SHERIFF"
        if inround.Value == true then
            script.Parent.Parent.Chosen.Visible = true
            wait(5)
            script.Parent.Parent.Chosen.Visible = false
        end
    elseif chosenRole.Value == "INNOCENT" then
        status.TextColor3 = Color3.new(3/255, 255/255, 19/255)
        status.Text = "INNOCENT"
        if inround.Value == true then
            script.Parent.Parent.Chosen.Visible = true
            wait(5)
            script.Parent.Parent.Chosen.Visible = false
        end
    elseif chosenRole.Value == "NEUTRAL" then
        status.TextColor3 = Color3.new(255/255, 255/255, 255/255)
        status.Text = "NEUTRAL"
        if inround.Value == true then
            script.Parent.Parent.Chosen.Visible = true
            wait(5)
            script.Parent.Parent.Chosen.Visible = false
        end
    end
end)

also the main script is an "script" and the second is an "local script"

1 answer

Log in to vote
4
Answered by
Nckripted 580 Moderation Voter
4 years ago

I noticed a couple problems with your script here:

  1. You are using a server sided value called chosenRole, but the problem is in the local script, you are looking for every time it is changed. What I mean is, everyone will be the murderer when they start the game. Instead, use a remote event, and fire it with the team that they will be on instead of changing a value.

  2. You are being heavily dependent on ReplicatedStorage, but the thing is, exploiters can easily change these values to their liking. Use remote events and functions instead of changing a value directly.

  3. Instead of complicating stuff and using Color3.new, use Color3.fromRGB, this will allow you to change color much more easily.

  4. There is a for loop that is not properly indented on line 77.

I’m sorry if I sound like a know it all, but the thing is, your script needs a major rewrite. It needs to be a bit more cleaner and safer from exploiters.

I’ll post another answer with some scripts you could use if you’d like.

0
Also, please note I made an error while typing. I meant that everybody would be Neutral, because the change is broadcasted everywhere. Nckripted 580 — 4y
0
that didnt help me, but it gave me an idea on how to make my game safer from exploiters VikkiVuk 74 — 4y
0
Glad to hear that! I’ll continue to look at the script and see if I can find any fixes for the issues you just listed. Nckripted 580 — 4y
0
also i have an question, how do you get the "if event is fired" value VikkiVuk 74 — 4y
View all comments (6 more)
0
Use OnServerEvent on a server script and OnClientEvent on a local script. For more information on remote events, go here: https://developer.roblox.com/en-us/articles/Remote-Functions-and-Events Nckripted 580 — 4y
0
umm its been awhile... VikkiVuk 74 — 4y
0
He literally said what you need to do lmao. Dovydas1118 1495 — 4y
0
Yes, and didnt work VikkiVuk 74 — 4y
0
I listed a resource on Remote Events and Functions. Did you read that? Nckripted 580 — 4y
0
I listed a resource on Remote Events and Functions. Did you read that? Nckripted 580 — 4y
Ad

Answer this question