• Announcement: Lua.org now officially recommends this forum as a meeting place for the Lua community
  • The forum is currently open to new registrations. The registration will close for a short period of time when reaching 500 active members, to upgrade the server resources.

Roblox Mute button not working in Roblox (1 Viewer)

SITUATION:

I have a rounds-based Roblox game and I have a mute button which I would like to have work when players are in the round. This code is from a script in serverscriptserver:


local roundzone = regionPart -- this is an invisible part surrounding the round that if a player touches I know they are in the round
playerinround = true
local roundsmusic = currentmap:FindFirstChild(chosenmap.Value).themesong -- different maps are cloned from server storage into a folder called currentmap

function inround(part)
local parent = part.Parent
if part.Parent:FindFirstChild("Humanoid") ~= nil then
local player = game.Players:GetPlayerFromCharacter(part.Parent)
if player ~= nil then
--playerinround = true
roundsmusic.Volume = 0
--if roundsmusic.Volume == 1 then roundsmusic.Volume = 0 else roundsmusic.Volume = 1 end
end
end
return playerinround
end

game.StarterGui.Mute.TextButton.Touched:Connect(inround) -- runs function when the button is touched

PROBLEM:

When I run this I get an error that says: Touched is not a valid member of TextButton "StarterGui.Mute.TextButton"

Would love any advice!
 

kevintdame

Newcomer
Joined
Dec 24, 2020
Messages
11
Reaction score
0
Hmmm. Having trouble seeing how this other situation applies. In the prior case 'winningplayer' was a variable. In this case Touched is an event right?
 

stetre

Member
Rank: I
Joined
Jan 8, 2020
Messages
45
Reaction score
28
Location
Italy
Website
github.com
As I wrote in the other thread, I don't know much about Roblox so I don't really know what Touched is.

I do know something about Lua, though, and if Touched is to be used as in the code you showed above, then:
1) it must be the name of a field of the table game.StarterGui.Mute.TextButton, and
2) its value must be an object (i.e. a table with methods) having a method called Connect().

A quick google search and I found the reference Roblox's TextButton object, but I can't find any field named Touched in it.
I see however a few fields whose values are of the type RBXScriptSignal, which does have a Connect() method.
Maybe Touched is a variable storing the name of one of those fields. You can check this easily by inserting print(Touched)
just before the faulty statement.
 
Top