Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 6 years ago
Edited 6 years ago

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

Log in to vote
3
Answered by
gitrog 326 Moderation Voter
6 years ago

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)

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 chess123mate 5873 — 6y
Ad
Log in to vote
-1
Answered by 6 years ago

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.

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. Creeperok 6 — 6y

Answer this question