Ok so heres the deal: I have this script and I want to to change the decal ID when these 2 certain players are in game, then change when they leave. Problem is,if they both join and if one leaves, it reverts, and the other one can still be in game and see it. Please help?
--Current script, "Mya" is name of the joke i have with friends, so do ignore local PreviousDecal = game.Workspace.RandomThing:FindFirstChild("Decal") if PreviousDecal then PreviousDecal:Destroy() end -- So theres only 1 local Mya = Instance.new("Decal") Mya.Parent = game.Workspace.RandomThing Mya.Texture = DECAL ID game.Players.PlayerAdded:connect(function(p) if p.UserId == 17408797 or 3976483464 then local Mya = game.Workspace.RandomThing:FindFirstChild("Decal") Mya.Texture = IDFORCOVERUP end end) game.Players.PlayerRemoving:connect(function(p) if p.UserId == 17408797 or 3976483464 then local Mya = game.Workspace.RandomThing:FindFirstChild("Decal") Mya.Texture = DECAL ID end end)
Any help appreicated.
You aren't checking if the other player is in the game also. Just simply add a for loop to scroll through all the players. If even one of the IDs match up, the for loop will return and not run the rest of the code. If it doesn't find any of them, the decal will remove.
Code:
local PreviousDecal = game.Workspace.RandomThing:FindFirstChild("Decal") if PreviousDecal then PreviousDecal:Destroy() end -- So theres only 1 local Mya = Instance.new("Decal") Mya.Parent = game.Workspace.RandomThing Mya.Texture = DECAL ID game.Players.PlayerAdded:connect(function(p) if p.UserId == 17408797 or 3976483464 then local Mya = game.Workspace.RandomThing:FindFirstChild("Decal") Mya.Texture = IDFORCOVERUP end end) game.Players.PlayerRemoving:connect(function() for _, p in pairs(game.Players:GetChildren()) do if p.UserId == 17408797 or 3976483464 then return true end end local Mya = game.Workspace.RandomThing:FindFirstChild("Decal") Mya.Texture = DECAL ID end)
You need a boolean value to check if they're both in game, and if they're both not in game. Below replace 'UserId == 0' with the IDs. Here's what you need to add:
p1 = false p2 = false game.Players.PlayerRemoving:connect(function(p) if p.UserId == 0 then p1 = true if p1 and p2 then -- Decal code end elseif p.UserId == 0 then p2 = true if p1 and p2 then -- Decal code end end end) game.Players.PlayerAdded:connect(function(p) if p.UserId == 0 then p1 = false if p1 == false and p2 == false then -- Remove Decal Code end elseif p.UserId == 0 then p2 = false if p1 == false and p2 == false then -- Remove Decal Code end end end)
local PreviousDecal = game.Workspace.RandomThing:FindFirstChild("Decal") if PreviousDecal then PreviousDecal:Destroy() end local Mya = Instance.new("Decal") Mya.Parent = game.Workspace.RandomThing Mya.Texture = DECAL ID -- set the decal id (before ppl join) local plr1 = false local plr2 = false function Reload() if plr1 and plr2 then Mya.Texture = SHOWED DECAL ID -- set the decal id ( after join ) else Mya.Texture = DECAL Id -- set the decal id after they leave end game.Players.PlayerAdded:connect(function(p) if p.UserId == 17408797 then -- id of first user plr1 = true elseif p.UserId == 3976483464 then -- id of second user plr2 = true end Reload() end) game.Players.PlayerRemoving:connect(function(p) if p.UserId == 17408797 then -- first id plr1 = false elseif p.UserId ==3976483464 then -- second id plr2 = false end Reload() end)
This should work EDIT: Explanation of not working thing especially for kingdom5. If You want to check are both players in game then I prefer adding two bolean variables and when some guy join change one of them to true (after that check are both variables set to true, if yes, set decal texture, if no, revert) You did script which didnt check both players. You just checked is one guy in game (note: If two people joined and one left then it didnt work too cause You reverted decam. So if You want to make this avaible when only one of these guys is in then just replace and by or in Reload function)