Hey uhh, I’m trying to make a Sans vs Chara game, and basically, if you join the game first, you’ll automatically be put on the Sans team. And if you’re on the Sans team, your body parts are supposed to go invis. However, that doesn’t happen. What’s wrong with this thing?
What do you want to achieve? Player goes invisible if on Sans team.
What is the issue? Player doesn’t go invisible. Yet in the output, it shows it’s working.
What solutions have you tried so far? Tried tweaking the code, same result. Here’s the code.
local Players = game.Players or game:GetService("Players")
local Teams = game.Teams
local Sans = Teams.Sans
local Chara = Teams.Chara
Players.PlayerAdded:Connect(function(Player)
if Sans.Taken.Value == false and Chara.Taken.Value == true or Chara.Taken.Value == false then
Player.RespawnLocation = game.Workspace["Sans Spawn"]
Player.Team = Sans
print(Player.Name.." is on the Sans team. Imagine joining first and then pressing fn+f9.")
Player.CharacterAdded:Connect(function(Character)
print(Character.Name.." added to workspace!")
local Children = Character:GetChildren()
for i = 1, #Children do
if Children[i].ClassName == "MeshPart" then
local MeshParts = Children[i]
MeshParts.Transparency = 1
print(MeshParts.Name..tostring(MeshParts.Transparency))
end
end
-- Character:Remove()
end)
Sans.Taken.Value = true
elseif Sans.Taken.Value == true and Chara.Taken.Value == false then
Player.RespawnLocation = game.Workspace["Chara Spawn"]
Player.Team = Chara
print(Player.Name.." is on the Chara team. Imagine joining first and then pressing fn+f9.")
end
end)
Removing the character just broke the free cam. So, I scrapped that.
Most of the things in this code are actually bogus / useless.
You don’t have to manually set the team when the player joins, because it automatically sets a team itself, and distributes the players equally. Just set both team’s AutoAssignable property to true. Of course if the “Sans” doesn’t set first, you’ll just have to do it manually.
Also, I notice how you manually set the player’s RespawnLocation to an Instance. I don’t know if that’s a SpawnLocation, but if it is, it’s not necessary. Player automatically spawn at their own team’s SpawnLocations.
Another thing, although this may be slightly advanced.
local Children = Character:GetChildren()
for i = 1, #Children do
if Children[i].ClassName == "MeshPart" then
local MeshParts = Children[i]
MeshParts.Transparency = 1
print(MeshParts.Name..tostring(MeshParts.Transparency))
end
end
You can use a special loop meant for looping through tables, like what :GetChildren() returns. It’s called a for in loop.
Here’s it’s syntax:
for keyOrIndex, value in table do
print(value) -- this will run for every item in the table.
end
So using this loop, your code may look like this:
for i, child in Character:GetChildren() do
if child.ClassName == "MeshPart" then
local MeshParts = child
MeshParts.Transparency = 1
print(MeshParts.Name..tostring(MeshParts.Transparency))
end
end
You’re responding to me, but I didn’t write the script. I think you should respond to him instead, because the only thing I corrected / edited was the loop.
You’re right though, there are a lot of nit-picks in this code, and I could go for hours.
This is just blatantly stupid, and thinking performance wise, a waste of CPU time.
You don’t have to redefine a new variable with a different identifier name just because you’ve just verified it’s type. Just continue on using the child identifier.
Are you saying when exclusively using the print function? Or, generally? Because if the not the latter, it’s still a safe method. If you were storing a concatenation of a number, or some other arbitrary type, it would still be verifying that it has to be a string.
Try this code, so when the CharacterAdded event is fired the transparent code has already been executed
local Players = game.Players or game:GetService("Players")
local Teams = game.Teams
local Sans = Teams.Sans
local Chara = Teams.Chara
Players.PlayerAdded:Connect(function(Player)
if Sans.Taken.Value == false and Chara.Taken.Value == true or Chara.Taken.Value == false then
Player.RespawnLocation = game.Workspace["Sans Spawn"]
Player.CharacterAdded:Connect(function(Character)
local Children = Character:GetChildren()
for i = 1, #Children do
if Children[i].ClassName == "MeshPart" then
local MeshParts = Children[i]
MeshParts.Transparency = 1
end
end
end)
Player.Team = Sans
print(Player.Name.." is on the Sans team. Imagine joining first and then pressing fn+f9.")
Sans.Taken.Value = true
elseif Sans.Taken.Value == true and Chara.Taken.Value == false then
Player.RespawnLocation = game.Workspace["Chara Spawn"]
Player.Team = Chara
print(Player.Name.." is on the Chara team. Imagine joining first and then pressing fn+f9.")
end
end)
And… this too didn’t work either. The output is showing that it’s working by sending me the prints, but the server isn’t registering the transparency change I guess.
I think the best way to handle this is to make them invisible through the Client, for example whenever for each character and whenever a character is added the client will make them invisible.
you can try using runservice and teleporting them for where they’re hidden except for the LocalPlayer, teleporting other players through LocalScript will not effect them.
You’re trying to make the player invisible? Here’s how I would do it:
local transparency = .9 -- the amount of transparency
for _, v in char:GetChildren do
if v:IsA("Accessory") then
v.Handle.Transparency = transparency
elseif v:IsA("BasePart") then
v.Transparency = transparency
end
end
This should be the basic format for doing anything related physical objects on the character.