1 | local sp = script.Parent |
2 |
3 | sp.Touched:connect( function (hit) |
4 | game.Players:GetPlayerFromCharacter(hit.Parent).PlayerGui:ClearAllChildren() |
5 | local gui = game.Lighting.Chase:Clone() |
6 | gui.Parent = game.Workspace.player.Character.Torso |
7 |
8 | end ) |
I had trouble trying to make this script clone the "Chase" audio into the torso of player that touched parent of the script. I want to know how can I make that to work. (The script above is my attemp of trying to make it work)
Hey Alexeeii,
:GetPlayerFromCharacter(Character)
method and set that as the variable.01 | local part = script.Parent; -- The part that will be touched. |
02 | local players = game:GetService( "Players" ); -- The Players Service |
03 | local lighting = game:GetService( "Lighting" ); -- The Lighting Service |
04 | local deb = false ; -- Debounce needed for cool down. (We don't want to make 3 Audios in Torso at one touch.) |
05 | local cooldown = 2 ; -- The amount of seconds the cool down will be. |
06 |
07 | part.Touched:Connect( function (hit) -- Anonymous function. |
08 | local hum = hit.Parent:FindFirstChild( "Humanoid" ); -- Humanoid variable (If there is one.) |
09 | if hum and not deb then -- Checks if there is a humanoid and if debounce is false. |
10 | deb = true ; -- Sets debounce to true so that it doesn't run this function until debounce is set back to false. |
11 | local char = hit.Parent; -- Variable for the Character. |
12 | local player = players:GetPlayerFromCharacter(char); -- Variable for the Player. |
13 | local music = lighting:WaitForChild( "Chase" ):Clone(); -- Variable for the audio in Lighting called "Chase". |
14 | local torso = char:FindFirstChild( "Torso" ) or char:WaitForChild( "UpperTorso" ); -- Variable for the Torso. |
15 |
~~ KingLoneCat