I’m trying to make a click of a button make a frame fade out, and i do not script. Therefore, i’ve been using local sources on the forums and none have worked out for me and i don’t know why.
This is the script i’ve been using:
game.parent.MouseButton1Click:connect(function()
local frame = script.Parent.Parent
local function StartRound()
repeat
frame.BackgroundTransparency = frame.BackgroundTransparency - 0.05;
wait(0.05);
until frame.BackgroundTransparency <= 0;
end
end)
Help is very much appreciated
PS: this is my first ever post so i would also appreciate it if you could tell me whether or not this is the right category
Next time use ``` for scripts, both in the beginning and in the end.
game.parent.MouseButton1Click:Connect(function() -- game.parent, wait what?
local frame = script.Parent.Parent
local function StartRound() -- you created a new function for each new click
repeat
frame.BackgroundTransparency = frame.BackgroundTransparency - 0.05; -- inconsistent semicolons
wait(0.05);
until frame.BackgroundTransparency <= 0;
end
end)
Why is this game.parent? Whaaaa??
You are creating functions inside the button which does nothing at all.
The function inside is not called.
This does not have any functionality, at all.
Furthermore, what button was supposed to be calling such an anonymous function? What’s your true goal of the button(as I’m confused over why there is a function inside the function)?
Transparency reaching 0 means it’s visible, not going transparent.
Change the name of game to something else. It’s already an inbuilt variable.
There is not property called parent in game. (game.parent does not exist.) It’s game.Parent. Capitalization matters.
Not only that, I suggest using Tweens. Here is an example of your script with tweens. I changed the name of game to _game.
local tweenService = game:GetService("TweenService")
_game.Parent.MouseButton1Click:connect(function()
local frame = script.Parent.Parent
-- Create a tween.
local info = TweenInfo.new(
1 -- How long in seconds the effect will take.
)
local tween = tweenService:Create(
frame,
info,
{ -- The properties to change, in this case, the transparency of the frame.
BackgroundTransparency = 0
}
)
-- Play the tween
tween:Play()
end)
It does. The lowercase property was deprecated in favour of the PascalCase property. Capitalisation matters in the sense that you avoid using a deprecated property and maintain consistency with the rest of your code.