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)
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)
Connect
not connect
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)