I am changing a morph script so that it will work a player hits a screen gui text button. Here is the script so far:
function Clicked()
local player = game.Players.LocalPlayer
local hit = player.Character.Name
print(hit)
local g = game.Workspace["501st Trooper"].Helmet:clone()
g.Parent = game.Workspace.hit
local C = g:GetChildren()
for i=1, #C do
if C[i].className == "UnionOperation" then
local W = Instance.new("Weld")
W.Part0 = g.Middle
W.Part1 = C[i]
local CJ = CFrame.new(g.Middle.Position)
local C0 = g.Middle.CFrame:inverse()*CJ
local C1 = C[i].CFrame:inverse()*CJ
W.C0 = C0
W.C1 = C1
W.Parent = g.Middle
end
local hit = script.Parent.Parent.Parent.Parent.Name
local Y = Instance.new("Weld")
Y.Part0 = game.Workspace.hit.Head
Y.Part1 = g.Middle
Y.C0 = CFrame.new(0, -.1, -.1)
Y.Parent = Y.Part0
end
local hit = script.Parent.Parent.Parent.Parent.Name
local h = g:GetChildren()
for i = 1, # h do
if h[i].className == "UnionOperation" then
h[i].Anchored = false
h[i].CanCollide = false
end
end
end
script.Parent.MouseButton1Click:connect(Clicked)
Here is the error/output:
Jexpler
15:52:39.907 - hit is not a valid member of Workspace
15:52:39.908 - Stack Begin
15:52:39.909 - Script 'Players.Jexpler.PlayerGui.ScreenGui.TextButton.Torso', Line 6
15:52:39.909 - Stack End

5 comments
Your script is pretty weird, is hit a part of the workspace?
It's a child of the text button
If you're using a screengui you wouldn't use function(hit), you would use MouseButton1Click. Function(hit) is only used for parts and instances.
The hit itsn't part of the function, it's an extra variable
And "hit" is a variable representing the physical local character