When multiple players join a game, even though I have scripted it not too, both players are “set” to the same dummy at the start of the cutscene. So, what I am trying to say is that my intent was it for to spawn the amount of dummies = the amount of players (up to four), and each dummy has the avatar of a different player. However, when two or more players get into the game, only one dummy is changed and the others dont spawn. Here is the code:
local dummies = {
[game.Workspace.People:FindFirstChild("Dummy 1")] = false,
[game.Workspace.People:FindFirstChild("Dummy 2")] = false,
[game.Workspace.People:FindFirstChild("Dummy 3")] = false,
[game.Workspace.People:FindFirstChild("Dummy 4")] = false
--etc..
}
local takenDummies = {}
--this table is a dictionary between
--key is player taking the dummy, value is the dummyObj
--this is a function changeAvatar
local function changeAvatar(plr,dummy)
local desc = game.Players:GetHumanoidDescriptionFromUserId(plr.UserId)
local humanoid = dummy.Humanoid
local animator = humanoid:WaitForChild("Animator")
local anim = dummy.Animation
local animTrack = animator:LoadAnimation(anim)
animTrack.Looped = true
dummy.Humanoid:ApplyDescription(desc)
for i,v in pairs(dummy:GetChildren()) do
if v:isA("MeshPart") or v.Name == "Head" and v.Name ~= "HumanoidRootPart" then
v.Transparency = 0
end
end
repeat wait()
until #game.Players:GetChildren() == workspace.lp.Value
animTrack:Play()
print("Animation is playing...")
end
local players = game:GetService("Players")
players.PlayerAdded:Connect(function(player)
for dummyObj, dummyIsTaken in pairs(dummies) do
if not dummyIsTaken then
print("Selected dummy is supposedly not taken...")
-- ^^ if the dummy is NOT taken/filled, then take it
for i,v in pairs(dummyObj:GetChildren()) do
if v:isA("MeshPart") or v.Name == "Head" and v.Name ~= "HumanoidRootPart" then
v.Transparency = 0
print("Transparency has been set to zero...")
end
if v:IsA("Accessory") then
for _, accessoryPart in pairs(v:GetChildren()) do
if accessoryPart.ClassName == "Part" or accessoryPart.ClassName == "MeshPart" then
accessoryPart.Transparency = 0 -- or whatever you define your transparency as
print("Transparency has been set to zero...")
end
end
end
if v.Name == "Head" then
v:FindFirstChild("face").Transparency = 0
print("Transparency has been set to zero...")
end
end
changeAvatar(player, dummyObj)
print("Avatar has been changed for ..", player, ". This player has control of ", dummyObj)
--mark it as filled
dummies[dummyObj] = true
--put the player into the takenDummies dict so that we can find the dummy object later
takenDummies[player] = dummyObj
print(dummies[dummyObj], takenDummies[player])
print("Dummy is true.")
break
end
end
end)
--End of the cutscene to remove the dummies that are spawned
game.Players.PlayerAdded:Connect(function(player)
wait(15)
local takenDummyObj = takenDummies[player] --variable for the "Taken" dummy
if takenDummyObj ~= nil then --making sure the dummy we are removing exists and is taken
--we want to set the entry in the DUMMIES table to false, not the takenDummies
dummies[takenDummyObj] = false
--then, we want to clear this player from the takenDummies tbl, as its no longer taken
takenDummies[player] = nil
end
print(takenDummyObj)
for i,v in pairs(takenDummyObj:GetChildren()) do
if v:isA("MeshPart") or v:isA("Part") then
v.Transparency = 1
end
if v:IsA("Accessory") then
for _, accessoryPart in pairs(v:GetChildren()) do
if accessoryPart.ClassName == "Part" or accessoryPart.ClassName == "MeshPart" then
accessoryPart.Transparency = 1 -- or whatever you define your transparency as
end
end
end
if v.Name == "Head" then
v:FindFirstChild("face").Transparency = 1
end
end
end)