I’m making a script that changes the entire player’s avatar to stone when they click a part. I don’t know the issue and i can’t locate it.
local srRoka = script.Parent
local click = srRoka.ClickDetector
local function eatIt(Player)
Player.Character.Humanoid.Health = Player.Character.Humanoid.Health + 200
print("player has gained health")
function StonePlayer(char)
local children = char:GetChildren()
for i, v in pairs(children) do
if v:IsA("BasePart") then
task.spawn(function()
local color = v.Color
local material = v.Material
v.Color = Color3.new(.5,.5,.5)
v.Material = Enum.Material.Stone
wait(5)
v.Color = color
v.Material = material
print("changed character to stone")
end)
end
end
end
end
click.MouseClick:Connect(eatIt)
You can’t change the material to Stone since it doesn’t exist.
Your function inside the click detector wasn’t executed.
Even if you changed the material of the body parts, the material won’t appear. I recommend overlaying a texture on the body parts.
function eatIt(Player)
local Character = Player.Character
local Humanoid = Character:FindFirstChild("Humanoid")
Humanoid.Health = Humanoid.Health + 200
print("player has gained health")
local function StonePlayer(char)
local children = char:GetChildren()
for i, v in pairs(children) do
if v:IsA("BasePart") then
task.spawn(function()
local color = v.Color
local material = v.Material
v.Color = Color3.new(.5,.5,.5)
v.Material = Enum.Material.Stone--there's no material called as Stone.
wait(5)
v.Color = color
v.Material = material
print("changed character to stone")
end)
end
end
end
StonePlayer(Character)--you forgot to execute the function StonePlayer.
end
local srRoka = script.Parent
local click = srRoka:WaitForChild("ClickDetector")
local function eatIt(Player)
local Character = Player.Character
local Humanoid = Character.Humanoid
Humanoid.Health += 200
local CharStuff = Character:GetChildren()
for i, v in ipairs(CharStuff) do
if v:IsA("BasePart") then
task.spawn(function()
local color = v.Color
local material = v.Material
v.Color = Color3.new(.5, .5, .5)
v.Material = Enum.Material.Stone
task.wait(5)
v.Color = color
v.Material = material
end)
end
end
end
click.MouseClick:Connect(eatIt)
I’m not sure why you have a function defined inside of a function like that, this only requires and works with a single function.
I’ve used ipairs() on the array as it’s more efficient than pairs() bare in mind that ipairs() is only valid for arrays and will work with dictionaries. I’ve replaced wait() with task.wait() as it’s more reliable/accurate and I shortened the arithmetic operation on the value assigned to the “Health” property of the fetched Humanoid instance.