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

What is wrong with this script?

Asked by 10 years ago
01x = script.Parent
02y = game.Workspace.Message.Text
03 
04function onClicked(mouse)
05 
06wait(1)
07Instance.new("Message", game.Workspace)
08wait(1)
09y = Player.Name.."clicked The button!"
10wait(3)
11y = ""
12 
13 
14end
15 
16x.ClickDetector.MouseClick:connect(onClicked)

2 answers

Log in to vote
3
Answered by
DataStore 530 Moderation Voter
10 years ago

1) You've not defined what 'Player' is anywhere, yet attempt to get its name.

2) You cannot reference a property in that way. When you create a variable and set it to the value of a property, the variable won't point to the property but rather become equal to whatever the value of the property is at that moment in time.

3) You shouldn't really create a new message every time unless you're deleting the old ones (which you weren't). Messages won't display unless their 'Text' property has something in it, meaning you can quite easily just create one and change that each time.

Here's how I'd do it with an anonymous function:

1local Message = Instance.new("Message", Workspace)
2 
3script.Parent.ClickDetector.MouseClick:connect(function(Player)
4    Message.Text = Player.Name .. " clicked the button!"
5    wait(3)
6    Message.Text = ""
7end)

Which is the same as:

1local Message = Instance.new("Message", Workspace)
2 
3function Clicked(Player)
4    Message.Text = Player.Name .. " clicked the button!"
5    wait(3)
6    Message.Text = ""
7end
8 
9script.Parent.ClickDetector.MouseClick:connect(Clicked)
0
Thanks chill22518 145 — 10y
Ad
Log in to vote
-2
Answered by 10 years ago

What is the output?

01x = script.Parent
02y = game.Workspace.Message.Text
03 
04function onClicked(mouse)
05 
06wait(1)
07Instance.new("Message", game.Workspace)
08wait(1)
09y = player.Name.."clicked The button!"
10wait(3)
11y = ""
12 
13 
14end
15 
16x.ClickDetector.MouseClick:connect(onClicked)

Answer this question