Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Can you help me with "Touched:connect" function?

I have:

script.Parent.Touched:connect(function(h)
[script]
end)

And i need this function could use h

player.PlayerGui.Gui.Button.MouseButton1Down:connect(function()
[script]
Part.Parent = h
end)

It should look like this:

script.Parent.Touched:connect(function(h)
if h.Name == "Test" then
player.PlayerGui.Gui.Button.Visible = true
end)

player.PlayerGui.Gui.Button.MouseButton1Down:connect(function()
local att = Instance.new("Attachment")
	att.Parent = h
end)

But "MouseButton1Down:connect" function don't know what is h

2 answers

✓ Accepted answer

Something like this would work. "H" is local to the Touched function you wrote. To make it usable by other functions, it must be defined outside of the Touched function.

local holdH = 0

script.Parent.Touched:connect(function(h)
holdH = h
if h.Name == "Test" then
player.PlayerGui.Gui.Button.Visible = true
end)

player.PlayerGui.Gui.Button.MouseButton1Down:connect(function()
local att = Instance.new("Attachment")
    att.Parent = holdH
end)

1 comment

0

Probably holdH = h should be inside the if statement and the MouseButton1Down connection should not be inside the script.Parent.Touched connection (or else you'll end up with many connections). Finally, use "Connect" not "connect". Nonetheless, the right idea, +1

Hello,

You did not define what is "player" and what is "h".

Please define them first, if something goes wrong, or a problem occurs, feel free to comment.

Sincerely,

Arti_BLOX.

1 comment

0

h is thing that touches the main Part "script.Parent.Touched:connect(function(h)" and this function know it, but i need second function know it. And I have "local player = game.Players.LocalPlayer" already.

This discussion is preserved as it was. New answers, comments, and votes are closed.