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

how can i make these two scripts into one?

hi guys, these functions do the exact same thing so can someone help me make them into 1 function instead of two

workspace.Footy.Red.Goal.Changed:connect(function()
script.Parent.Frame.Scorer.Text = "GOAL - " .. workspace.Goals.Ball.LastKick.Value:upper() .. "   GOALS -" .. game.Players:FindFirstChild(workspace.Goals.Ball.LastKick.Value).leaderstats.Goals.Value
script.Parent.Parent.ImageLabel.Image = "http://www.roblox.com/asset/?id=" .. game.Players:FindFirstChild(workspace.Goals.Ball.LastKick.Value).hiddenstats.flagy.Value
script.Parent.Frame.Time.Text = workspace.minutes.Value .. "'"
script.Parent.Parent.Visible = true
wait(25)
script.Parent.Parent.Visible = false
end)

workspace.Footy.Blue.Goal.Changed:connect(function()
script.Parent.Frame.Scorer.Text = "GOAL - " .. workspace.Goals.Ball.LastKick.Value:upper() .. "   GOALS -" .. game.Players:FindFirstChild(workspace.Goals.Ball.LastKick.Value).leaderstats.Goals.Value
script.Parent.Parent.ImageLabel.Image = "http://www.roblox.com/asset/?id=" .. game.Players:FindFirstChild(workspace.Goals.Ball.LastKick.Value).hiddenstats.flagy.Value
script.Parent.Frame.Time.Text = workspace.minutes.Value .. "'"
script.Parent.Parent.Visible = true
wait(25)
script.Parent.Parent.Visible = false
end)

1 answer

You need to do this:

function Change()
script.Parent.Frame.Scorer.Text = "GOAL - " .. workspace.Goals.Ball.LastKick.Value:upper() .. "   	GOALS -" .. game.Players:FindFirstChild	(workspace.Goals.Ball.LastKick.Value).leaderstats.Goals.Value
script.Parent.Parent.ImageLabel.Image = "http://www.roblox.com/asset/?id=" .. 	game.Players:FindFirstChild(workspace.Goals.Ball.LastKick.Value).hiddenstats.flagy.Value
script.Parent.Frame.Time.Text = workspace.minutes.Value .. "'"
script.Parent.Parent.Visible = true
wait(25)
script.Parent.Parent.Visible = false
end	

workspace.Footy.Blue.Goal.Changed:connect(Change) --Calls Change() if blue goal changes,
workspace.Footy.Red.Goal.Changed:connect(Change) -- Or red goal

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