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

Can you detect if a player doesn't have a bool value?

Asked by
MattVSNNL 620 Moderation Voter
3 years ago

I'm trying to make a murder mystery game to see if I can do it but I want to do that the murder doesn't become the sheriff too, I wrote a code but it won't work, Can anyone help me?

Module script:

local functions = {}

local serverStorage = game:GetService("ServerStorage")
local sword = serverStorage:WaitForChild("Assets"):WaitForChild("ClassicSword")
local gun = serverStorage:WaitForChild("Assets"):WaitForChild("HyperlaserGun")

functions.chooseRandomSherrif = function()
    local players = game:GetService("Players"):GetPlayers()
    local Sherrif = players[math.random(1,#players)]
    local clonedGun = gun:Clone()
    local sherrifTag = Instance.new("BoolValue")
    if Sherrif:WaitForChild("Murder") then
        sherrifTag.Name = "Sherrif"
        sherrifTag.Parent = Sherrif.Character

        clonedGun.Parent = Sherrif.Backpack
    end
end

functions.chooseRandomMurder = function()
    local players = game:GetService("Players"):GetPlayers()
    local Murder = players[math.random(1,#players)]
    local clonedSword = sword:Clone()
    local murderTag = Instance.new("BoolValue")

    if not Murder:WaitForChild("Sherrif") then
        murderTag.Name = "Murder"
        murderTag.Parent = Murder.Character

        clonedSword.Parent = Murder.Backpack
    end
end

return functions

0
You can do 'if not Player.BoolValue' then... radiant_Light203 1166 — 3y

2 answers

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

Here's a better idea, use attributes. They're a new feature that are pretty much the replacement for value objects.

An example of how you can fit this into your game:

function AssignSherrif()
    local Player
    repeat
        Player = Players:GetChildren()[math.random(0,#Players:GetChildren())]
    until
        not Player:GetAttribute("Role") = "Murderer"
    Player:SetAttribute("Role", "Sherrif")
    -- other stuff
end

function AssignMurderer()
    local Player
    repeat
        Player = Players:GetChildren()[math.random(0,#Players:GetChildren())]
    until
        not Player:GetAttribute("Role") = "Sherrif"
    Player:SetAttribute("Role", "Murderer")
    -- other stuff
end
Ad
Log in to vote
0
Answered by 3 years ago

This:

if not player.BoolValue then
    --some code
end
0
Doesn't work sorry MattVSNNL 620 — 3y

Answer this question