I inserted a part and placed my gui inside it, I put a script inside my gui to set it to playergui ontouch but nothing works, is this an issue with the script or gui
Here's the guigiver script
local debounce = false function getPlayer(humanoid) local players = game.Players:children() for i = 1, #players do if players[i].Character.Humanoid == humanoid then return players[i] end end return nil end function onTouch(part) local human = part.Parent:findFirstChild("Humanoid") if (human ~= nil) and debounce == false then debounce = true local player = getPlayer(human) if (player == nil) then return end script.Parent:clone().Parent = player.PlayerGui wait(2) debounce = false player.PlayerGui.OnTouchGui:remove() wait() debounce = false wait(5) end end script.Parent.Parent.Touched:connect(onTouch)
And here's the maingui
sp = script.Parent Frame = sp:WaitForChild("Frame") Boss = Frame:WaitForChild("Boss") Health = Frame:WaitForChild("Health") Red = Frame:WaitForChild("Red") HealthCount = Frame:WaitForChild("HealthCount") BossName = Frame:WaitForChild("BossName") Humanoid = nil while true do if Boss.Value ~= nil then if Boss.Value:FindFirstChild("Torso") then sp.BossGui.Adornee = Boss.Value.Torso sp.BossGui.Enabled = true end Frame.Visible = true BossName.Text = Boss.Value.Name Humanoid = Boss.Value:FindFirstChild("Humanoid") if Humanoid then Health.Size = UDim2.new(Humanoid.Health/Humanoid.MaxHealth,0,1,0) if Red.Size.X.Scale > Health.Size.X.Scale then Red:TweenSize(UDim2.new(Humanoid.Health/Humanoid.MaxHealth,0,1,0), 1, 1, (Red.Size.X.Scale-Health.Size.X.Scale)*10, true) else Red.Size = UDim2.new(Humanoid.Health/Humanoid.MaxHealth,0,1,0) end HealthCount.Text = math.floor(Humanoid.Health).." | "..Humanoid.MaxHealth --Health.BackgroundColor3 = Color3.new(1-(Humanoid.Health/Humanoid.MaxHealth),Humanoid.Health/Humanoid.MaxHealth,0) else sp.BossGui.Adornee = nil sp.BossGui.Enabled = false Frame.Visible = false end if Boss.Value.Parent == nil then Boss.Value = nil sp.BossGui.Adornee = nil sp.BossGui.Enabled = false Frame.Visible = false end else sp.BossGui.Adornee = nil sp.BossGui.Enabled = false Frame.Visible = false end wait() end
Any ideas on issues?
You've got a few issues. They're all in your guigiver script.
On line 4, there is no function called :children. It would be :GetChildren
. You could also do game.Players:GetPlayers
.
You never defined what humanoid was before you made the if statement.
This isn't exactly a problem, but I HIGHLY advise you to not use :Remove
, as that is a deprecated function. That means it could be removed later, and there will be no such thing as :Remove
. Use :Destroy
instead.
clone() should be capitalized Clone(). Not sure if there’s anything else but look in output and it will tell you everything you need to know.
Do you seriously rely on others to spoon-feed you? You clearly made some mistakes, missed ends, and using a deprecated latter. :connect
is deprecated if you don't know, so use :Connect
. Also, functions need to be local, global functions are bad practice to use since it's less efficient than local functions and has a small impact on performance. Local functions on the other head have an advantage over global variables since it's easier for scoping and organization.
local debounce = false local function getPlayer(humanoid) local players = game.Players:Children() for i = 1, #players do if players[i].Character.Humanoid == humanoid then return players[i] end end end return nil end local function onTouch(part) local human = part.Parent:FindFirstChild("Humanoid") if (human ~= nil) and debounce == false then debounce = true local player = getPlayer(human) if (player == nil) then return end script.Parent:clone().Parent = player.PlayerGui wait(2) debounce = false player.PlayerGui.OnTouchGui:remove() wait() debounce = false wait(5) end end end script.Parent.Parent.Touched:Connect(onTouch)
I just fixed your script but didn't check for any errors except for your spellings and ends., if it doesn't work de-bug it your self.
Again, global variables. Also, note that HumanoidRootPart
exists in all R6 and R15 characters, so never use Torso
or UpperTorso
when you can use HumanoidRootPart
.
local sp = script.Parent local Frame = sp:WaitForChild("Frame") local Boss = Frame:WaitForChild("Boss") local Health = Frame:WaitForChild("Health") local Red = Frame:WaitForChild("Red") local HealthCount = Frame:WaitForChild("HealthCount") local BossName = Frame:WaitForChild("BossName") local Humanoid = nil while true do if Boss.Value ~= nil then if Boss.Value:FindFirstChild("HumanoidRootPart") then sp.BossGui.Adornee = Boss.Value.HumanoidRootPart sp.BossGui.Enabled = true end Frame.Visible = true BossName.Text = Boss.Value.Name Humanoid = Boss.Value:FindFirstChild("Humanoid") if Humanoid then Health.Size = UDim2.new(Humanoid.Health/Humanoid.MaxHealth,0,1,0) if Red.Size.X.Scale > Health.Size.X.Scale then Red:TweenSize(UDim2.new(Humanoid.Health/Humanoid.MaxHealth,0,1,0), 1, 1, (Red.Size.X.Scale-Health.Size.X.Scale)*10, true) else Red.Size = UDim2.new(Humanoid.Health/Humanoid.MaxHealth,0,1,0) end HealthCount.Text = math.floor(Humanoid.Health).." | "..Humanoid.MaxHealth --Health.BackgroundColor3 = Color3.new(1-(Humanoid.Health/Humanoid.MaxHealth),Humanoid.Health/Humanoid.MaxHealth,0) else sp.BossGui.Adornee = nil sp.BossGui.Enabled = false Frame.Visible = false end if Boss.Value.Parent == nil then Boss.Value = nil sp.BossGui.Adornee = nil sp.BossGui.Enabled = false Frame.Visible = false end else sp.BossGui.Adornee = nil sp.BossGui.Enabled = false Frame.Visible = false end wait() end
No errors in this script except for a few which I fixed, if it doesn't work, debug it since I'm not spoon-feeding you.