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 9 years ago
x = script.Parent
y = game.Workspace.Message.Text

function onClicked(mouse)

wait(1)
Instance.new("Message", game.Workspace)
wait(1)
y = Player.Name.."clicked The button!"
wait(3)
y = ""


end

x.ClickDetector.MouseClick:connect(onClicked)


2 answers

Log in to vote
3
Answered by
DataStore 530 Moderation Voter
9 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:

local Message = Instance.new("Message", Workspace)

script.Parent.ClickDetector.MouseClick:connect(function(Player)
    Message.Text = Player.Name .. " clicked the button!"
    wait(3)
    Message.Text = ""
end)

Which is the same as:

local Message = Instance.new("Message", Workspace)

function Clicked(Player)
    Message.Text = Player.Name .. " clicked the button!"
    wait(3)
    Message.Text = ""
end

script.Parent.ClickDetector.MouseClick:connect(Clicked)
0
Thanks chill22518 145 — 9y
Ad
Log in to vote
-2
Answered by 9 years ago

What is the output?

x = script.Parent
y = game.Workspace.Message.Text

function onClicked(mouse)

wait(1)
Instance.new("Message", game.Workspace)
wait(1)
y = player.Name.."clicked The button!"
wait(3)
y = ""


end

x.ClickDetector.MouseClick:connect(onClicked)

Answer this question