How is it not working for you? Have you attempted to apply basic debugging to this situation first or reference the Developer Hub for help and API references?
You can change a few things. This probably wont fix it, but it will make the code better.
FIrst of, change connect to Connect. Change the for loop to an in pairs loop (for i, v in pairs() do). You can also use IsA() instead of class name. You can also put local before you define the function.
local function onTouch(hit)
local d = hit.Parent:GetChildren()
for i, v in next, d do -- pairs is the same thing as next
if v:IsA("Model") then
-- code
end
end
end
I suppose to do that, it just too long for me to explain, i did post description briefly and others do understand what i’m saying, especially with images.
I don’t mind to explain it again, Best for everybody to understaind If I upload on YT. It will take a while…
@Eternalove_fan32, He already mentioned above that it is a server script.
@Joshua7ninjaX , your post is very confusing. From what I can tell, you are trying to parent a clone into each person’s PlayerGui. You can achieve this by replacing:
for _,plr in pairs(game.Players:GetPlayers()) do
d[i].Clone().Parent = plr.PlayerGui.UMP.CurrentlyMorphs
end
This will clone everything that is a model inside of Players into everyone’s PlayerGui at that specified location. I am not sure if you wanted something different, but this is what I assume you’re asking for based on the information provided.
function onTouched(hit)
local d = hit.Parent:GetChildren()
for i,v_plr in pairs(game.Players:GetPlayers(d)) do
if v:IsA(“Model”) then – this will highlight Morphs(Arm1,Arm2.Chest,Head1,Leg1,Leg2)
d[i].Clone().Parent = plr.PlayerGui.UMP.CurrentlyMorphs – Invidual Player
end
end
end end Underline with red?
Although using i pairs would be better as @colbert2677 has indicated in similar posts in the past (you can implement that if you’d like )
I used a serverscript in the part , once touched , data is compared with data in an array to see if there’s a match, if yes then…
local players = game:GetService("Players")
local people ={
"Joshua7ninjaX";--though I recommend using ids instead
}
script.Parent.Touched:Connect(function(hit)
local touchedPlayer = players:GetPlayerFromCharacter(hit.Parent)
if not table.find(people,touchedPlayer.Name) then return
end --nothing happens if that player's name isnt found
for _, loopedPlayer in pairs(players:GetPlayers()) do
if loopedPlayer:FindFirstChild("PlayerGui") then
coroutine.wrap(function()
local morphgui = loopedPlayer.PlayerGui.UMD.CurrentlyMorphs
morphgui.Visible = true
--[[ wait(3.3)
morphgui.Visible = false]]
end)()
end
end
end)
I might have done an unnecessary loop, click here
local players = game:GetService("Players")
local people ={
"Joshua7ninjaX";--though I recommend using ids instead
}
script.Parent.Touched:Connect(function(hit)
local touchedPlayer = players:GetPlayerFromCharacter(hit.Parent)
if not table.find(people,touchedPlayer.Name) then return
end --nothing happens if that player's name isnt found
local player = players.LocalPlayer
if player:FindFirstChild("PlayerGui") then
local morphgui = player.PlayerGui.UMD.CurrentlyMorphs
morphgui.Visible = true
--[[ wait(3.3)
morphgui.Visible = false]]
end)
end
end)
U posted this and thank anyway, i put bold here from your helped. Then PixelZombieX probably watch the video and post correctly.
for i,v in pairs(d) do
If v:IsA(“Model”) then
–Do stuf
–
function touch(hit)
local d = hit.Parent:GetChildren() for i,v in pairs(d) do if v:IsA(“Model”) then – this will highlight Morphs(Arm1,Arm2.Chest,Head1,Leg1,Leg2)
local plr = game.Players:GetPlayerFromCharacter(hit.Parent) – Invidual Player
if hit.Parent:FindFirstChild(“Humanoid”) then
d[i]:Clone().Parent = plr.PlayerGui.UMD.CurrentlyMorphs
end
end
end
end