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

How can i make this script to clone Audio from lighting to players torso?

Asked by 7 years ago
Edited 7 years ago
1local sp = script.Parent
2 
3sp.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)

0
p.s. This script must work with Filtering Enabled Unity_456 47 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago

Hey Alexeeii,

I have found the issue in your script however, I'm sort of confused about some things. First of all, I am not sure as to why you are clearing all the children under PlayerGui. Some of them are quiet important and are pre-loaded for your Player's needs. Also, you tried to set the parent of the Gui by searching for player in workspace however, you never defined that as the variable or anything of that sort. That won't find the player in the workspace that touched the part. For that you need to use the :GetPlayerFromCharacter(Character) method and set that as the variable.

There's quiet a lot of things wrong with your code and some that confuse me so, I'll just go over the code that I personally prepared which explains to you step by step what each line of code does and I think that it's pretty efficient so I'll show you that.

01local part = script.Parent; -- The part that will be touched.
02local players = game:GetService("Players"); -- The Players Service
03local lighting = game:GetService("Lighting"); -- The Lighting Service
04local deb = false; -- Debounce needed for cool down. (We don't want to make 3 Audios in Torso at one touch.)
05local cooldown = 2; -- The amount of seconds the cool down will be.
06 
07part.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 
View all 21 lines...

Well, I hope I helped and thank you for your time.

~~ KingLoneCat

0
The script doesnt seem to work in studio. Unity_456 47 — 7y
0
I have tried it and it doesnt put the audio into the player's torso Unity_456 47 — 7y
0
Are you sure the audio is named "Chase" and it's in Lighting? KingLoneCat 2642 — 7y
0
Yes. Unity_456 47 — 7y
View all comments (3 more)
0
Wait, It worked only when i removed the admin script from the workspace. Unity_456 47 — 7y
0
Thank you for the help! Unity_456 47 — 7y
0
No problem. KingLoneCat 2642 — 7y
Ad

Answer this question