Hello! You should change your topic category for #help-and-feedback:scripting-support
Also, your script doesn’t work because you are checking "if v.ClassName == "Part" then
" while all parts of the character are “MeshPart
”!
So there is a basic solution:
First, let’s define the variables:
local Player = game:GetService("Players").LocalPlayer --> The local Player
local Button = script.Parent
local Debounce = true
local toIgnore = "HumanoidRootPart"
Now we are going to create the functions, to simplify everything, we are going to use the variables we created. A local function
is used to store functions, it is widely used to improve your code and make it cleaner.
local function ChangeTransparency(Parent, Transparency)
for Index, Value in pairs(Parent:GetDescendants()) do
--Now, `:IsA ("Class")` will check if the object belongs to "Class", if it is, it will return true, otherwise, false.
if Value:IsA("BasePart") and Value.Name ~= toIgnore then
Value.Transparency = Transparency
end
end
end
Now we are going to create the main local function
, which will be called when the button is activated.
local function onButtonActivated()
--> Here we will check if the player has a character and the debounce
if Player.Character and Debounce then
--> Player.Character just return the current character of LocalPlayer
local Character = Player.Character
Debounce = false
--> Let's call the function, the first parameter (Character) will be called Parent, and the second, Transparency
ChangeTransparency(Character, 1)
wait(5) --> Time to wait!
--> Let's call another time to change the transparency back
ChangeTransparency(Character, 0)
wait(10) --> Wait.. zZzzzZ
Debounce = true
end
end
Lastly, let’s connect the functions, we only need to connect the function onButtonActivated
to be executed when the button is pressed.
Button.Activated:Connect(onButtonActivated)
As for the fact that your game is lagged, there are many factors that can differentiate the cause of the delay, such as your game map, loops while true do
, serverside :Connects()
without :Disconnect()
.
You should evaluate it a little more and tell us specifically.