I want to click a button, and if that button is clicked, I want an effect to play for that button i clicked.
The Issue
I’m very new to programming, so excuse the bad code, but my issue here is that I’m getting the children in the button folder, but when I try and play the effect for the button I clicked, it only plays on one of them. Both buttons can be clicked to play the effect, but again, the effect only plays on one of them.
So far I’ve tried searching on the forums and documentation sites, but I’ve struggled to find the correct solution. So far I’ve used a for loop to get all the buttons inside the button folder, that’s it. I’m stuck here.
I’m playing the effects on the client, firing a remote event to the server script that spawns a part, and taking the effects from a module script and playing those on the client in the same script as a button. (Sorry if I’m explaining this wrong, again, I’m new to programming haha)
This is where I find buttons - This is in a module script
-- Find Buttons
local button
for _, v in ipairs(buttonFolder:GetChildren()) do
button = v
end
This is the click effect - Also in the same module script
function buttonEffect.buttonClick() -- Button Click
print(button)
local rotateValue = math.random(-5, 5)
local clickSound = soundsFolder.Click:Clone()
button.Effect.Ripple:Emit(1)
button.Effect.Puff:Emit(5)
clickSound.Parent = button
clickSound:Play()
tweenService:Create(highlight, TweenInfo.new(0.075), {OutlineColor = Color3.fromRGB(255, 98, 153)}):Play()
tweenService:Create(button, TweenInfo.new(0.075), {Color = Color3.fromRGB(181, 96, 126)}):Play()
tweenService:Create(button, TweenInfo.new(0.1), {Size = Vector3.new(sizeX - 0.1, sizeY - 0.1, sizeZ - 0.1)}):Play() -- Shrink Button
tweenService:Create(button, TweenInfo.new(0.1), {Position = Vector3.new(posX, posY - 0.3, posZ + 0.3)}):Play() -- Move Button Down
tweenService:Create(button, TweenInfo.new(0.1), {Orientation = Vector3.new(rotX + rotateValue, rotY + rotateValue, rotZ + rotateValue)}):Play() -- Rotate Button
task.wait(0.1)
if hovered == true then
tweenService:Create(button, TweenInfo.new(0.1), {Size = Vector3.new(sizeX + 0.05, sizeY + 0.05, sizeZ + 0.05)}):Play()
else
tweenService:Create(button, TweenInfo.new(0.1), {Size = Vector3.new(sizeX, sizeY, sizeZ)}):Play()
end
tweenService:Create(button, TweenInfo.new(0.1), {Orientation = Vector3.new(rotX, rotY, rotZ)}):Play()
tweenService:Create(button, TweenInfo.new(0.1), {Position = Vector3.new(posX, posY, posZ)}):Play()
tweenService:Create(highlight, TweenInfo.new(0.075), {OutlineColor = Color3.fromRGB(255, 255, 255)}):Play()
tweenService:Create(button, TweenInfo.new(0.075), {Color = Color3.fromRGB(119, 166, 181)}):Play()
clickSound:Destroy()
end
return buttonEffect
So I’m getting the buttons in the button folder, but it’s not letting me play the effect depending on the button I clicked, here is my part spawn button, the other button has the similar script. Any help is appreciated!