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

What's wrong with this script? (Answered)

So, I've made a Goal-Line technology script, it's inside a part and there's two scripts. One of them makes the "GOAL" sound, this works perfectly, but one of them should make a Message saying "GOAL!", but it's not working. --- The script is only enabled when a football goes over the line. I'm a beginner scripter and this is still in BETA, here is the script:

script.Parent.Touched:connect(function(otherPart)
	if otherPart.name == "Ball" or otherPart.name == "Ball" then
		m = Instance.new("Message")
m.Parent = Workspace
m.Text = "Goal!"
	wait(4)
	end
end)

1 comment

1

Capitalize the .Name

4 answers

✓ Accepted answer

Capitalization is key. You also forgot to remove the message.

script.Parent.Touched:connect(function(otherPart)
	if otherPart.Name == "Ball" then
		m = Instance.new("Message")
		m.Parent = Workspace
		m.Text = "Goal!"
		wait(4)
		m:Destroy()
    end
end)

Well, first, 'name' should be capital. (So, .Name).

Second, why would you check if the name equals ball or ball? You only need to check if it equals ball once...

Third, you never delete the message (which is what you want, right?) If you're going to delete the message use the Destroy() method. If you want it to stay there and never leave, there it no point to do wait(4) at the end of your script.

script.Parent.Touched:connect(function(otherPart)
	if otherPart.Name == "Ball" then
		m = Instance.new("Message")
		m.Parent = Workspace
		m.Text = "Goal!"
		wait(4)
		m:Destroy()
	end
end)

This is a pretty good script, with only two small things wrong with it.

1. As everyone has said, name at line 2 needs to be capitalized into Name (so it would look like if otherPart.Name ==...

2. At line 2, you put if otherPart.name == "Ball"twice, which doesn't change anything. Either there was a typo and you put the word "Ball" twice, or you just need to take out the last or if otherPart.name == "Ball".

Otherwise this script should work fine when the Ball touches the part! (which I assume is behind the line).

1 comment

0

Also (again, as multiple people have pointed out), your message won't go away unless you put something to remove it (such as m:Destroy() at line 7).

I've had goal-line technology for nearly a year now... The script also teleports the ball back to the center circle. Here you go!

Put in a normal script in Workspace

team1=game.Teams["team1"] --Change
team2=game.Teams["team2"] --Change
score=1

--Dont touch anything below
model=game.Workspace.Ball
backup=model:clone()

function regen(a)
	model:remove()
	new_model=backup:clone()
	new_model.Parent=game.Workspace
	new_model:MakeJoints()
	model=game.Workspace.Ball
end

function onG1(part)
	if part.Name=="Ball" then
		game.Workspace.Team2Score.Value=(game.Workspace.Team2Score.Value+score)
		regen(a)
	end
end

function onG2(part)
	if part.Name=="Ball" then
		game.Workspace.Team1Score.Value=(game.Workspace.Team1Score.Value+score)
		regen(a)
	end
end

game.Workspace.Goal1.Touched:connect(onG1)
game.Workspace.Goal2.Touched:connect(onG2)

Put in a normal script in the score GUI

team1=game.Teams["team1"] --Change
team2=game.Teams["team2"] --Change
type="-"

-- DON'T TOUCH ANYTHING BELOW THIS
while true do
	wait(0.1)
	script.Parent.Label1.Text=team1.Name.." "..type.." "..game.Workspace.Team1Score.Value
	script.Parent.Label2.Text=team2.Name.." "..type.." "..game.Workspace.Team2Score.Value
end

The Scoreboard (You'll see what I mean) needs to be in a Frame (You can re-size if how you want) and inside this frame, 2 text boxes. They are named Label1 & Label2. In Label1, change the text to "Team1 Score" and in Label2, change it to "Team1 Score" (WITHOUT THE QUOTATION MARKS!) Make sure the script and 2 text boxes are in the same directory in that frame.

I also have 2 scripts in the ball that I forgot (As it's been about a year) if they are linked to this or not, so add them anyways!

Inside the ball, in a script named Hit

function onTouched(hit)
local torso = hit.Parent:findFirstChild("Torso")
if torso~=nil then
game.Workspace.GKWait1.CanCollide = false
game.Workspace.GKWait1a.CanCollide = false
game.Workspace.GKWait1b.CanCollide = false
game.Workspace.GKWait1c.CanCollide = false
wait(1)
script.Parent.PFix.Disabled = false
wait(2)
script.Disabled = true
end
end

script.Parent.Touched:connect(onTouched)

The other is named Touch

function onTouched(hit)
if hit.Parent:FindFirstChild("Humanoid")~=nil then
X = game.Players:playerFromCharacter(hit.Parent)
if X.TeamColor==BrickColor.new("Bright green")then
game.Workspace.Hit.Value = BrickColor.new("Bright green")
end end end

script.Parent.Touched:connect(onTouched)

function onTouched(hit1)
if hit1.Parent:FindFirstChild("Humanoid")~=nil then
X = game.Players:playerFromCharacter(hit1.Parent)
if X.TeamColor==BrickColor.new("Bright blue")then
game.Workspace.Hit.Value = BrickColor.new("Bright blue")
end end end

script.Parent.Touched:connect(onTouched)

function onTouched(hit2)
if hit2.Parent:FindFirstChild("Humanoid")~=nil then
X = game.Players:playerFromCharacter(hit2.Parent)
if X.TeamColor==BrickColor.new("Camo")then
game.Workspace.Hit.Value = BrickColor.new("Camo")
end end end

script.Parent.Touched:connect(onTouched)

function onTouched(hit3)
if hit3.Parent:FindFirstChild("Humanoid")~=nil then
X = game.Players:playerFromCharacter(hit3.Parent)
if X.TeamColor==BrickColor.new("Really blue")then
game.Workspace.Hit.Value = BrickColor.new("Really blue")
end end end

script.Parent.Touched:connect(onTouched)

function onTouched(hit4)
if hit4.Parent:FindFirstChild("Humanoid")~=nil then
X = game.Players:playerFromCharacter(hit4.Parent)
if X.TeamColor==BrickColor.new("Bright green") or X.TeamColor==BrickColor.new("Camo") then
game.Workspace.Scorer1.Value = X.Name
end end end

script.Parent.Touched:connect(onTouched)

function onTouched(hit5)
if hit5.Parent:FindFirstChild("Humanoid")~=nil then
X = game.Players:playerFromCharacter(hit5.Parent)
if X.TeamColor==BrickColor.new("Bright blue") or X.TeamColor==BrickColor.new("Really blue") then
game.Workspace.Scorer2.Value = X.Name
end end end

script.Parent.Touched:connect(onTouched)

I'm pretty sure that's all you need. Feel free to use it or any other ideas you got!

1 comment

0

You might want to edit that. In case he doesn't have 'GK' as a descendant of Workspace.

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