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

(GUI) Why this script doesn't work?

Asked by 10 years ago
function onButtonClicked()
game.Workspace.character.Torso.Instance.new("Sparkles")
end

script.Parent.MouseButton1Click:connect(onButtonClicked)

When the TextButton is clicked, sparkles should appear in the player who clicked torso but it doesn't work :(

0
Is there something called "character" in workspace? I'm pretty sure the name of the model of the player's character has the name of the player. GoldenPhysics 474 — 10y
0
PlayerWhoClicked doesn't work too brickgame38 50 — 10y

2 answers

Log in to vote
3
Answered by
M39a9am3R 3210 Moderation Voter Community Moderator
10 years ago

In your script, you should be getting the error Instance is not a valid member of Torso. This is because you can not go straight into making a new object when you're in the location. You want to make the new object first, then place it in the desired location. Fortunately, there is an optional second argument to Instance.new() that allows you to set a location for the object. You would also get the error, character is not a valid member of workspace. This is because in workspace, there is no model or object named character. Your script should look more like.

--Put in a local script for LocalPlayer to work.
function onButtonClicked()
Instance.new("Sparkles", game.Players.LocalPlayer.Character.Torso)
end

script.Parent.MouseButton1Click:connect(onButtonClicked)

Check out this wiki article if I did not explain Instance.new well enough.

You can also check here to see how LocalPlayer works.

Ad
Log in to vote
-1
Answered by 10 years ago

You have to insert a click detector into the part

script.Parent.ClickDetector.MouseClick:connect(onButtonClicked)

Here is a script for spawing one

Instance.new("ClickDetector",game.Workspace:FindFirstChild("PartNameGoesHere")

0
I want to insert Sparkles into the torso of the player who clicked the (GUI!) textbutton brickgame38 50 — 10y

Answer this question