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

How can I add a script inside a character?

Hello, I have a script that automatically adds inside the character via "StarterPlayer > StarterCharacterScripts". But now, I need to do something different. I need to do an action (click or touch) to get it. I know how to do the "action" and I have a clone of my script located inside "ServerStorage". I know how to clone it. But I dont know how to find the character to add it into him. Any help please? I am not requesting for a script. I know how to write it but I just dont know how to make that small thing that adds it to your character (I know how to add it to a Backpack for example.).

Thank You.

local button = script.Parent.Parent


script.Parent.MouseClick:connect(function(plr)
	local copy = game.ServerStorage["Grapple Hook Boi"]:Clone() -- The script
	copy.Parent = -- How to add to a character?
end)

4 comments

0

use the parameter of MouseClick?

0

Hmm? This script is actually one I made with a Backpack script. Its working. I just need to know how to parent it into a humanoid.

0

so you want it to parent to the player's humanoid

0

I mean the character, not himanoid, sorry. Where all the accessories and body parts are.

2 answers

✓ Accepted answer

You have the player parameter of MouseClick which you've named plr. You can get the character by accessing the Character property of the player. Keep in mind that the character might not exist, so you need to use an if statement for that.

script.Parent.MouseClick:Connect(function(plr)
	local copy = game.ServerStorage["Grapple Hook Boi"]:Clone()

	local character = plr.Character
	if character then
		copy.Parent = character
	end
end)
PS: Use Connect not connect

1 comment

0

Thank you very much. It worked. :)

im pretty sure that you want to parent your script to the player's character, so you could do that by using the parameter of the MouseClick event which gets the player that clicked it like this example:

script.Parent.MouseClick:Connect(function(plr) -- parameter  use :Connect
	plr.Character.Humanoid:TakeDamage(10) -- the parameter gets the player not the character
end)

also :Connect() is decaperated, instead use :Connect().

local button = script.Parent.Parent


script.Parent.MouseClick:Connect(function(plr)
    local copy = game.ServerStorage["Grapple Hook Boi"]:Clone() 
    copy.Parent = plr.Character
end)

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