local function setGhost(v:BasePart)
if not v:IsA("BasePart") then continue end
v.Material = Enum.Material.ForceField
v.BrickColor = BrickColor.new("Medium stone grey")
end)
game:GetService("ReplicatedStorage").GhostEvent.OnServerEvent:Connect(function(player)
player:LoadCharacter()
local char = player.Character or player.CharacterAdded:Wait()
char:SetAttribute("Died",true)
char:SetAttribute("Hidden",true)
char:SetAttribute("CantHide",true)
char.ChildAdded:Connect(setGhost)
for _, v in char:GetDescendants() do
setGhost(v)
end
end)
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)
char.Humanoid.Died:Connect(function()
player:LoadCharacter()
player.Character:SetAttribute("Died",true)
player.Character:SetAttribute("Hidden",true)
player.Character:SetAttribute("CantHide",true)
for i, v in pairs(player.Character:GetChildren()) do
if v:IsA("BasePart") or v:IsA("MeshPart") or v:IsA("Part") then
v.Material = Enum.Material.ForceField
v.BrickColor = BrickColor.new("Medium stone grey")
elseif v:IsA("Accessory") then
v:WaitForChild("Handle").Material = Enum.Material.ForceField
v:WaitForChild("Handle").BrickColor = BrickColor.new("Medium stone grey")
end
end
end)
end)
end)
And it still doesn’t work, i’m supposing it maybe has something to do with my own accessorys that bugs it?
Some accesorries doesn’t have SpecialMesh inside it, i think your character have these accessories, try this script, its should work for all types of accesories!
game:GetService("ReplicatedStorage").GhostEvent.OnServerEvent:Connect(function(player)
player.CharacterAdded:Once(function()
task.wait(0.1)
player.Character:SetAttribute("Died",true)
player.Character:SetAttribute("Hidden",true)
player.Character:SetAttribute("CantHide",true)
for i, v in pairs(player.Character:GetDescendants()) do
if v:IsA("BasePart") or v:IsA('MeshPart') then
v.Material = Enum.Material.ForceField
v.BrickColor = BrickColor.new("Medium stone grey")
elseif v:IsA("Accessory") then
v:WaitForChild("Handle").Material = Enum.Material.ForceField
v:WaitForChild("Handle").BrickColor = BrickColor.new("Medium stone grey")
if v:WaitForChild('Handle'):IsA('MeshPart') then
v:WaitForChild('Handle').TextureID = "rbxassetid://"
else
v:WaitForChild('Handle'):FindFirstChildOfClass('SpecialMesh').TextureId = "rbxassetid://"
end
end
end
end)
player:LoadCharacter()
end)
I understand why you are using continue at that point, but using that will only let the remainder of the code to be executed if v:IsA("BasePart") evaluates to be true, you added the check which is:
if not v:IsA("BasePart") continue end
This negates the existence of other classes like MeshParts,
MeshPart and BaseParts are completely separate classes and therefore, following your is not feasible, however we can improve it like this, here’s the final solution:
game:GetService("ReplicatedStorage").GhostEvent.OnServerEvent:Connect(function(player)
player:LoadCharacter()
player.Character:SetAttribute("Died",true)
player.Character:SetAttribute("Hidden",true)
player.Character:SetAttribute("CantHide",true)
for i, v in player.Character:GetDescendants() do
if v:IsA("BasePart") or v:IsA("MeshPart") or v:IsA("Part") then
v.Material = Enum.Material.ForceField
v.BrickColor = BrickColor.new("Medium stone grey")
end
end
end)
Welp, i give up. I’ll just temporarily disable the script for now and maybe if i get a solution in my head i’ll use it. Thanks to everyone who tried helping.
game:GetService("ReplicatedStorage").GhostEvent.OnServerEvent:Connect(function(player)
player:LoadCharacter()
task.wait(1)
player.Character:SetAttribute("Died",true)
player.Character:SetAttribute("Hidden",true)
player.Character:SetAttribute("CantHide",true)
for i, v in pairs(player.Character:GetDescendants()) do
if v:IsA("BasePart") or v:IsA("MeshPart") or v:IsA("Part") then
v.Material = Enum.Material.ForceField
v.BrickColor = BrickColor.new("Medium stone grey")
elseif v:IsA("Accessory") then
v:WaitForChild("Handle").Material = Enum.Material.ForceField
v:WaitForChild("Handle").BrickColor = BrickColor.new("Medium stone grey")
end
end
end)
It’s because of the player:LoadCharacter(), all it needed was a task.wait() before it.
Anyways, thanks to everyone who helped, appereciate it.
(Looking back at the scripts you gave me, i realized i forgot the task.wait() in them )
local function setGhost(v:BasePart)
if not v:IsA("BasePart") then continue end
v.Material = Enum.Material.ForceField
v.BrickColor = BrickColor.new("Medium stone grey")
end)
game:GetService("ReplicatedStorage").GhostEvent.OnServerEvent:Connect(function(player)
player:LoadCharacter()
local char = player.Character or player.CharacterAdded:Wait()
char:SetAttribute("Died",true)
char:SetAttribute("Hidden",true)
char:SetAttribute("CantHide",true)
char.DescendantAdded:Connect(setGhost)
for _, v in char:GetDescendants() do
setGhost(v)
end
end)
Do consider trying this as it does no useless checks and does not wait overly long
Sorry for the confusion and delay in response. I took some extra time to research meshParts and their inheritance from baseParts, and it seems that’s right.
Learning about meshParts actually come under baseParts, thanks…
In my experience, I’ve treated them separately in code (which might not have been entirely accurate). This was my core point, not the continue statement.
But yes, in reference baseParts and Meshparts, they might be something I probably wasn’t aware of, but still, even though I’ve treated them separately in code, I’ll definitely verify meshpart and basePart myself when I can, as roblox studio is not opening for me at the moment.
And, I definitely write my own responses, clarity is key, thank you.
Instead of task.wait, I think, Player.CharacterAdded:Wait() or Player.CharacterAppearanceLoaded:Wait() might be more reliable as these don’t assume the character will exactly only take 1 second in physics-heartbeat-time to load.
Just a suggestion at this point, as I think this would be an additional helpful info, and I haven’t tested the latter ever before: