local part = workspace.TestPart
local screenGuiName = "TestGui"
local function onTouch(otherPart)
local character = otherPart.Parent
local humanoid = character:FindFirstChildWhichIsA("Humanoid")
if humanoid then
local player = game.Players:GetPlayerFromCharacter(character)
local playerGui = player:FindFirstChild("PlayerGui")
local screenGui = playerGui:FindFirstChild(screenGuiName)
if screenGui then
screenGui.Enabled = false
end
end
end
part.Touched:Connect(onTouch)
It won’t disable the UI once the player has touched the part. How can i make this work?
Local scripts do not run if it is a descendant of workspace. Try placing the script in the ScreenGui.
Also, it is a local script meaning it can’t affect other people except the client running it. I would first set the player variable to game.Players.LocalPlayer and make it so only if the player’s character touches it, then disable the GUI.
local parts = {
workspace.TestPart1,
workspace.TestPart2,
workspace.TestPart3,
}
local screenGuiName = "TestGui"
local function onTouch(otherPart)
local character = otherPart.Parent
local humanoid = character:FindFirstChildWhichIsA("Humanoid")
if humanoid then
local player = game.Players:GetPlayerFromCharacter(character)
local playerGui = player:FindFirstChild("PlayerGui")
local screenGui = playerGui:FindFirstChild(screenGuiName)
if screenGui then
screenGui.Enabled = false
end
end
end
for _, part in ipairs(parts) do
part.Touched:Connect(onTouch)
end
I rewrote it, So i could add more “TestPart”(s)
Would this work if (For example) i made 100 TestParts. Or is there an easier way i could make it, So it reads Every single part with the name “TestPart”?