Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

What's wrong with this audio victory script?

The script is supposed to play the corresponding audio when one team gets a certain amount of points. Everything seems to be fine, but it doesn't play the audio when the team wins. Please help!

function RedChecker(points) -- This is fired when the number of points on the red team changes
    if points >= 100 then -- This then checks if the number of points is over or equal to a certain number of points, in this case 100
        game.Workspace.RedSound:Play() -- This will play the audio for when red team wins, you can change the "RedSound" to whatever you name your sound
    end
end

-- This is exactly the same as the function for red team, instead this is for blue team.
function BlueChecker(points)
    if points >= 100 then
        game.Workspace.BlueSound:Play()
    end
end

game.Workspace.RedPoints.Changed:connect(RedChecker)-- RedPoints would be the name of the IntValue for the red team
game.Workspace.BluePoints.Changed:connect(BlueChecker) -- BluePoints would be the name of the IntValue for the blue team

1 answer

The Changed event's argument is a string value, which is the property changed of the item, which cannot be compared to a number. Instead, use this code:

function RedChecker(points) -- This is fired when the number of points on the red team changes
    if points >= 100 then -- This then checks if the number of points is over or equal to a certain number of points, in this case 100
        game.Workspace.RedSound:Play() -- This will play the audio for when red team wins, you can change the "RedSound" to whatever you name your sound
    end
end

-- This is exactly the same as the function for red team, instead this is for blue team.
function BlueChecker(points)
    if points >= 100 then
        game.Workspace.BlueSound:Play()
    end
end

game.Workspace.RedPoints.Changed:connect(function()
	RedChecker(game.Workspace.RedPoints.Value)
end) -- RedPoints would be the name of the IntValue for the red team
game.Workspace.BluePoints.Changed:connect(function()
	BlueChecker(game.Workspace.BluePoints.Value)
end) -- BluePoints would be the name of the IntValue for the blue team

1 comment

0

Still not working...

This discussion is preserved as it was. New answers, comments, and votes are closed.