Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

What's wrong with this script? (Answered)

Asked by 10 years ago

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:

1script.Parent.Touched:connect(function(otherPart)
2    if otherPart.name == "Ball" or otherPart.name == "Ball" then
3        m = Instance.new("Message")
4m.Parent = Workspace
5m.Text = "Goal!"
6    wait(4)
7    end
8end)
1
Capitalize the .Name OniiCh_n 410 — 10y

4 answers

Log in to vote
1
Answered by
Shawnyg 4330 Trusted Badge of Merit Snack Break Moderation Voter Community Moderator
10 years ago

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

1script.Parent.Touched:connect(function(otherPart)
2    if otherPart.Name == "Ball" then
3        m = Instance.new("Message")
4        m.Parent = Workspace
5        m.Text = "Goal!"
6        wait(4)
7        m:Destroy()
8    end
9end)
Ad
Log in to vote
1
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
10 years ago

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.

1script.Parent.Touched:connect(function(otherPart)
2    if otherPart.Name == "Ball" then
3        m = Instance.new("Message")
4        m.Parent = Workspace
5        m.Text = "Goal!"
6        wait(4)
7        m:Destroy()
8    end
9end)
Log in to vote
1
Answered by
emite1000 335 Moderation Voter
10 years ago

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).

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). emite1000 335 — 10y
Log in to vote
0
Answered by 10 years ago

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

01team1=game.Teams["team1"] --Change
02team2=game.Teams["team2"] --Change
03score=1
04 
05--Dont touch anything below
06model=game.Workspace.Ball
07backup=model:clone()
08 
09function regen(a)
10    model:remove()
11    new_model=backup:clone()
12    new_model.Parent=game.Workspace
13    new_model:MakeJoints()
14    model=game.Workspace.Ball
15end
View all 32 lines...

Put in a normal script in the score GUI

01team1=game.Teams["team1"] --Change
02team2=game.Teams["team2"] --Change
03type="-"
04 
05-- DON'T TOUCH ANYTHING BELOW THIS
06while true do
07    wait(0.1)
08    script.Parent.Label1.Text=team1.Name.." "..type.." "..game.Workspace.Team1Score.Value
09    script.Parent.Label2.Text=team2.Name.." "..type.." "..game.Workspace.Team2Score.Value
10end

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

01function onTouched(hit)
02local torso = hit.Parent:findFirstChild("Torso")
03if torso~=nil then
04game.Workspace.GKWait1.CanCollide = false
05game.Workspace.GKWait1a.CanCollide = false
06game.Workspace.GKWait1b.CanCollide = false
07game.Workspace.GKWait1c.CanCollide = false
08wait(1)
09script.Parent.PFix.Disabled = false
10wait(2)
11script.Disabled = true
12end
13end
14 
15script.Parent.Touched:connect(onTouched)

The other is named Touch

01function onTouched(hit)
02if hit.Parent:FindFirstChild("Humanoid")~=nil then
03X = game.Players:playerFromCharacter(hit.Parent)
04if X.TeamColor==BrickColor.new("Bright green")then
05game.Workspace.Hit.Value = BrickColor.new("Bright green")
06end end end
07 
08script.Parent.Touched:connect(onTouched)
09 
10function onTouched(hit1)
11if hit1.Parent:FindFirstChild("Humanoid")~=nil then
12X = game.Players:playerFromCharacter(hit1.Parent)
13if X.TeamColor==BrickColor.new("Bright blue")then
14game.Workspace.Hit.Value = BrickColor.new("Bright blue")
15end end end
View all 53 lines...

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

0
You might want to edit that. In case he doesn't have 'GK' as a descendant of Workspace. Shawnyg 4330 — 10y

Answer this question