How to make a murder type round based script?

I am making a game similar to murder type of games, basically, when the round starts you are teleported to a spawn, but it is not working. Here is the code.

--SpyxSpy main script

local spawns = {"Spawn1", "Spawn2", "Spawn3", "Spawn4", "Spawn5", "Spawn6"}

local selectedSpawn = spawns[math.random(1, #spawns)]

local Teleport = selectedSpawn

local spawn = workspace[selectedSpawn]

local Roles = {"Scientist", "Spy", "Soldier"}
local RoleMaxes = {6, 1, 2, 1}
local filled = {0, 0, 0, 0}
local function chooseRole()
    local open = {}
    for i = 1, #Roles do
        if filled[i] < RoleMaxes[i] then
            table.insert(open, i)
        end
    end
    local randomOpen = open[math.random(1, #open)]
    filled[randomOpen] = filled[randomOpen] + 1
    return Roles[randomOpen]
end

local selectedRole = chooseRole()
print(selectedRole)
if selectedRole == "Scientist" then
	game.StarterGui.ClassGui.Frame.TextLabel.TextSize = 50
	game.StarterGui.ClassGui.Frame.TextLabel.Text = "Scientist, stick with soldiers!"
	wait(2)
	game.StarterGui.ClassGui.Frame.Visible = false
end
if selectedRole == "Soldier" then
	game.StarterGui.ClassGui.Frame.TextLabel.TextSize = 50
	game.StarterGui.ClassGui.Frame.TextLabel.Text = "Soldier, protect scientists against the spy!"
	wait(2)
	game.StarterGui.ClassGui.Frame.Visible = false
end
if selectedRole == "Spy" then
	game.StarterGui.ClassGui.Frame.TextLabel.TextSize = 50
	game.StarterGui.ClassGui.Frame.TextLabel.Text = "Spy, kill soldiers and scientists, and gather data!"
	wait(2)
	game.StarterGui.ClassGui.Frame.Visible = false
end
local Pos = script.Parent.Parent:findFirstChild(Teleport)
Player:moveTo(Pos.Position)
2 Likes

The StarterGui contents are cloned into the PlayerGui when the player spawns (assuming Players.CharacterAutoLoads is false).

You need to edit PlayerGui, using a Remote. Also, Instance::findFirstChild and Model::moveTo are deprecated; use Instance::FindFirstChild and Model::MoveTo instead.

2 Likes

Thank you, but could you explain that to me a little bit? I am confused

He’s saying to use a Remote Event fired by the server to change the PlayerGui.

local RemoteEvent = game:GetService("ReplicatedStorage"):WaitForChild("ChangeGuiText") --//The Remote Event that is fired via server script to change the GUI text.
local TextLabel = script.Parent --//The TextLabel being changed.

RemoteEvent.OnClientEvent:Connect(function(Text) --//An event that activates whenever the RemoteEvent is fired.
    TextLabel.Text = Text --//Change the text accordingly.
end)

The code above is just an example, and if you were gonna use it you would need to create a local script inside of the GUI and then use RemoteEvent:FireAllClients() for it to be activated for everyone.

I don’t know how outdated this might be, but you can at least still grasp the techniques from this old masterpiece of a tutorial by Stickmasterluke:

Part of the ROBLOX University coding tutorial, specifically “Mad Bloxxer”, which is essentially a murder mystery styled game.

1 Like

Thank you, I have already tried using those tutorials, but they don’t work.

Have you defined Player?
Are you properly setting the position? [An alternative could be Torso.CFrame = Pos.CFrame
Are there any errors in your output?

1 Like