Hey guys! I hope y’all doing very very well! Being direct, I’m trying to give a specific player on the server the ability to see different GUI’s but the problem is that I didn’t find some way to do that.
So if you are chosen to be the “Monster” then the server will give your character a BoolValue called “Monster” and then set it to true but if there is no monster on the server then another player will wake up.
I know there’s a lot of good people here, so if you can give me a hand with this, even if it’s a small one, I’ll be very very grateful to you!
Here’s the script (LocalScript):
player.Character:FindFirstChild('Monster')
if player.Character.Monster then
print('There's a Monster')
elseif not player.Character:FindFirstChild('Monster') then
local PlayersQuantity = #game.Players:GetPlayers()
if PlayersQuantity == 4 then
for i, v in pairs(game.Players:GetPlayers()) do
v[1].Character:FindFirstChild('Monster')
v[2].Character:FindFirstChild('Monster')
v[3].Character:FindFirstChild('Monster')
v[4].Character:FindFirstChild('Monster')
if not v.Character:FindFirstChild('Monster') then
wait(13.6)
game.ReplicatedStorage:WaitForChild('RemoteEvents').WakeUpOtherMonster.WakeUpTroll:FireServer()
print("There's no Monsters")
end
end
end
This is the error I got:
I don’t know if it gives that error because it’s a LocalScript, and it should be on a ServerScript, but what I think the problem is, is that the machine thinks to search the number “1” on the Player’s character (v), but I don’t know other way to select a specific player of the server (for example: only the 3rd player on the server)
local Players = game:GetService("Players") -- Getting Service
-- something
local PlayersList = Players:GetPlayers() -- :GetPlayers return array of all player
local RandomPlayer = PlayersList[math.random(#PlayersList)] -- random number between 1 and amount of player, then use that number as index.
--We get the table of players so that we can iterate over it
local players = game:GetService("Players"):GetPlayers()
--we now iterate over the players table
for _, xyz in pairs(players) do
--we see if a player has the monster bool value
if xyz:FindFirstChildWhichIsA("BoolValue") then
--we access the monster's gui
local monsterGui = xyz.PlayerGui
--we setthe gui only for the monster to true
monsterGui.Whatevergui.Visible = true
end
end
Yes, but I want the server to search into a specific players, if your player doesn’t have the Monster BoolValue, then it makes a for loop to check if no one in the server has it, and If no one has the BoolValue then we call the Troll
player.Character:FindFirstChild('Monster')
if player.Character.Monster then
print("There's a Monster")
elseif not player.Character:FindFirstChild('Monster') then
local monsters = 0
for i, v in pairs(game.Players:GetPlayers()) do
local char = v.Character
if char:FindFirstChild("Monster") then
--is a monster
monsters += 1
else
--not a monster
end
end
if monsters == 0 then --no monsters
task.wait(13.6)
game.ReplicatedStorage:WaitForChild('RemoteEvents').WakeUpOtherMonster.WakeUpTroll:FireServer()
print("There's no Monsters")
end
end
local player = nil
player.Character:FindFirstChild('Monster')
if player.Character.Monster then
print("There's a Monster")
elseif not player.Character:FindFirstChild('Monster') then
local monsters = 0
for i, v in pairs(game.Players:GetPlayers()) do
local char = v.Character
if char:FindFirstChild("Monster") then
--is a monster
monsters += 1
else
--not a monster
end
end
if monsters == 0 then --no monsters
local randPlr = game.Players:GetPlayers()[math.random(1, #game.Players:GetPlayers())]
local randChar = randPlr.Character
local MonsterVal = Instance.new("BoolValue")
MonsterVal.Name = "Monster"
MonsterVal.Value = true
MonsterVal.Parent = randChar
task.wait(13.6)
game.ReplicatedStorage:WaitForChild('RemoteEvents').WakeUpOtherMonster.WakeUpTroll:FireServer()
print("There's no Monsters")
end
end
This creates a new monster by creating a BoolValue instance and parenting it to a random player’s character.
This is kind of hectic. Declare a variable for the Monster instance and check if(variable) then rather than if character.Monster. Will also allow you to access it later without having to index the character again for the same instance.
These are improvements which can be adopted later, the main task at hand is fixing the functionality of the script, I dislike straying too far from the original source material as it results in the code being less of the original poster’s own work.
Having a variable to define an instance (that you will be accessing more than once) does not stray too far and is, generally, a good practice. But, to each their own I guess.
Thank you so much for your help! This helps me not only advance on my scripting abilities but to expand my knowledge too! This works as planned, , Have a nice and lucky day-life !