local sp = script.Parent sp.Touched:connect(function(hit) game.Players:GetPlayerFromCharacter(hit.Parent).PlayerGui:ClearAllChildren() local gui = game.Lighting.Chase:Clone() gui.Parent = game.Workspace.player.Character.Torso 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.local part = script.Parent; -- The part that will be touched. local players = game:GetService("Players"); -- The Players Service local lighting = game:GetService("Lighting"); -- The Lighting Service local deb = false; -- Debounce needed for cool down. (We don't want to make 3 Audios in Torso at one touch.) local cooldown = 2; -- The amount of seconds the cool down will be. part.Touched:Connect(function(hit) -- Anonymous function. local hum = hit.Parent:FindFirstChild("Humanoid"); -- Humanoid variable (If there is one.) if hum and not deb then -- Checks if there is a humanoid and if debounce is false. deb = true; -- Sets debounce to true so that it doesn't run this function until debounce is set back to false. local char = hit.Parent; -- Variable for the Character. local player = players:GetPlayerFromCharacter(char); -- Variable for the Player. local music = lighting:WaitForChild("Chase"):Clone(); -- Variable for the audio in Lighting called "Chase". local torso = char:FindFirstChild("Torso") or char:WaitForChild("UpperTorso"); -- Variable for the Torso. music.Parent = torso; -- Sets the Parent of the music to the Torso. wait(cooldown) -- Does the cool down. deb = false; -- Sets debounce back to false so that the code can be run again. end -- end for the if statement end) -- end for the anonymous function.
~~ KingLoneCat