✓ Accepted answer
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.
local part = script.Parent;
local players = game:GetService("Players");
local lighting = game:GetService("Lighting");
local deb = false;
local cooldown = 2;
part.Touched:Connect(function(hit)
local hum = hit.Parent:FindFirstChild("Humanoid");
if hum and not deb then
deb = true;
local char = hit.Parent;
local player = players:GetPlayerFromCharacter(char);
local music = lighting:WaitForChild("Chase"):Clone();
local torso = char:FindFirstChild("Torso") or char:WaitForChild("UpperTorso");
music.Parent = torso;
wait(cooldown)
deb = false;
end
end)
##Well, I hope I helped and thank you for your time.
~~ KingLoneCat
1 comment
p.s. This script must work with Filtering Enabled