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

How do you run an "On Clicked" Command through a GUI button?

Its just a simple question, see I think I figured out how to change the player model but heres what I dont understand.

local button = script.Parent 
function buttonClicked()
    player.Character = copiedModel
	print ("It worked?")
end
button.MouseButton1Click:connect(buttonClicked)

I added some stuff to it. It says player and copiedModel are a nil value?

I was wondering if anyone knew how to possibly run that code through a GUI button. So when the player clicks the GUI he/she will change into the model.

Its just a simple question, nothing to heavy. Like I usually ask XD

2 answers

✓ Accepted answer

so your script is meant to be like:

local button = script.Parent -- script is inside the button

function buttonClicked()
	player.Character = copiedModel
	print("It Worked?")
end

button.MouseButton1Down:connect(buttonClicked)

if that works, and you say player and copiedModel are a nil value? make sure to specify in the script what the player actually is using local

local player = game.Players.LocalPlayer

and Copied Model... It depends if you're cloning it

local copiedModel = game.Workspace.Model:Clone() -- put where the model is located
copiedModel.Parent = game.Workspace --put where you want it to be

Although the player can't become a model if you want to know how to change the character look at this video: https://www.youtube.com/watch?v=2ibudXNxZ3A , or this: https://www.youtube.com/watch?v=c5pLIx3PsN8 , https://www.youtube.com/watch?v=AMk-pBlxgNQ .

if you want the model to become a child of the player use

copiedModel.Parent = player -- may need to change this

so it should look like this

local player = game.Players.LocalPlayer
local copiedModel = game.Workspace.Model:Clone() -- put where the model is located
copiedModel.Parent = game.Workspace --put where you want it to be (or Player)

local button = script.Parent -- script is inside the button

function buttonClicked()
	player.Character = copiedModel
	print("It Worked?")
end

button.MouseButton1Down:connect(buttonClicked)

1 comment

0

Although I did accept it as an answer the player goes invisible and cant move. But its progress toward my final goal.

To detect a button click, you need to set up a function and an event that uses it:

local button=script.Parent --(this is assuming the script is inside the button)
function buttonClicked()
    --You can do stuff here
end
button.MouseButton1Click:connect(buttonClicked)

I hope this helped!

3 comments

0

local copiedModel = game.Workspace.StarterCharacter local button = script.Parent function buttonClicked() player.Character = copiedModel end button.MouseButton1Click:connect(buttonClicked)

0

Sorry I didnt mean to post that but it says player is a nil value?

0

You have to define 'player' as a variable first.

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