i’ve been trying for an hour to get this gui to work, but it doesn’t, what happens is, my script turns up the transparency on the gui’s backgroundtransparency, but on the game itself, nothing happens, i’ve tried using a localscript, but that made absolutely nothing happen at all, not even the prints, any ideas why? i can’t record, so have this image since it still shows what i mean
script.Parent.Touched:Connect(function(hit)
local img = game.Players.LocalPlayer.PlayerGui.black.Frame
local counter = 0
while true do
task.wait(0.1)
counter = counter + 1
img.BackgroundTransparency = img.BackgroundTransparency - 0.1
if counter == 10 then
print("10 reached")
break
end
end
while true do
task.wait(0.1)
counter = counter - 1
img.BackgroundTransparency = img.BackgroundTransparency + 0.1
if counter == 0 then
print("0 reached")
break
end
end
end)
The frame’s path is inside the event which is not the best idea.
A debounce is missing, meaning this will get called multiple times which is what’s making your transparency go outside the range.
The local script appears to be located inside a part, instead of somewhere like StarterPlayerScripts.
A while loop is being used for a situation that can be done by using a for loop or TweenService.
You are not checking whether the hit parameter is a player or just another instance colliding with the part.
You are not checking if the player hitting the part is the local player. If you intend it to be activated by any player touching it, remove the hit.Parent.Name ~= player.Name part.
local TweenService = game:GetService('TweenService');
local img = game.Players.LocalPlayer:WaitForChild('PlayerGui'):WaitForChild('black'):WaitForChild('Frame');
local path = workspace:WaitForChild('Part');
local debounce = false;
path.Touched:Connect(function(hit)
if not hit.Parent:FindFirstChild('Humanoid') or debounce then return end;
debounce = true;
local Tween = TweenService:Create(img,TweenInfo.new(.1,Enum.EasingStyle.Linear,Enum.EasingDirection.Out,0,true),{BackgroundTransparency = 0});
Tween:Play()
Tween.Completed:Wait()
debounce = false;
end)
This should work if placed correctly. If you need to change the speed of transparency, change the first number inside TweenInfo.new.