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

(GUI) Why this script doesn't work?

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 :(

2 comments

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.

0

PlayerWhoClicked doesn't work too

2 answers

✓ Accepted answer

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.

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

1 comment

0

I want to insert Sparkles into the torso of the player who clicked the (GUI!) textbutton

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