Hi, I am running out of ideas about making this script. So, I am making a story game where of course is a dialogsystem with NPC´s and random players. But theres a main character that is being choosen random from the players. Normaly if I use the random player dialog system the main character is being called with his real playername. But I want the main character to be called son all the time. And if theres more then 1 player the son should be skipped and it will take a diffrent player. Anyways my problem is that the son is still being called with his real playername or sometimes it doesnt even work.
I used an if statement before but that didnt work. Then I tried to use Pcall, I dont know if Pcall is the right choice because Pcall is normaly being used in datastores as I heard. Does anybody know how I can make this script work?
Oh and the script is supposed to detect how many players are in a game. If theres only one player
it cant skip the son and the player will just be choosen all the time and called son. But if theres more then 1 player and the son has ben choosen then its supposed to skip the son and pick a diffrent player. And if the son has not ben choosen at the first time it will just continue with the player that was choosen.
I am out of ideas with this script and I dont think I made this script well. Does anybody have some ideas or should I remake this script?
function SetRandomPlayerText(word)
Message = word
RandomPlayer = nil
wait()
RandomPlayer = Players:GetChildren()[math.random(1, #Players:GetChildren())]
local succes, otherplayer = pcall(function()
RandomPlayer.Name = game.Workspace.Son.SonName.Value
end)
local PlayerCount = #Players:GetChildren()
if succes and PlayerCount == 1 then
print("succes theres only 1 player")
PlayerName.Value = "Son" -- Sets the PlayerName to a random player's name
wait() --
PlayerImage:FireAllClients(RandomPlayer) -- Sets the image to a random player's head
for i = 1, #Message do
Text.Value = string.sub(Message, 1, i)
TypeSound() -- Plays the typing sound
wait(0.04)
end
elseif succes and PlayerCount > 1 then
print("succes but theres more than 1 player")
RandomPlayer = Players:GetChildren()[math.random(1, #Players:GetChildren())]
elseif otherplayer and PlayerCount > 1 then
print("son has not been chosen")
PlayerName.Value = RandomPlayer.Name -- Sets the PlayerName to a random player's name
wait()
PlayerImage:FireAllClients(RandomPlayer) -- Sets the image to a random player's head
for i = 1, #Message do
Text.Value = string.sub(Message, 1, i)
TypeSound()
wait(0.04)
end
end
end
if somebody doesnt understand something about the script please tell me.
Any help is appreciated!