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

How can I add a script inside a character?

Asked by 6 years ago
Edited 6 years ago

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)
0
use the parameter of MouseClick? User#23365 30 — 6y
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. HeyItzDanniee 252 — 6y
0
so you want it to parent to the player's humanoid User#23365 30 — 6y
0
I mean the character, not himanoid, sorry. Where all the accessories and body parts are. HeyItzDanniee 252 — 6y

2 answers

Log in to vote
1
Answered by
RayCurse 1518 Moderation Voter
6 years ago
Edited 6 years ago

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
0
Thank you very much. It worked. :) HeyItzDanniee 252 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

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)

Answer this question