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

How do i use the Humanoid Touched event(easy question, im just dum)?

Im in Roblox API looking at how to make a event fire when a player touches something, but it gives no example or syntax really. I dont want to just copy paste this to do what i want if it aint gonna work. Here is the website im looking at

http://wiki.roblox.com/index.php?title=API:Class/Humanoid/Touched

How would i use this?

here is the box script

local Character = game.Players.LocalPlayer
local part = script.Parent
_G.DieNibba = function()
	part:Destroy()
end
repeat wait() until _G.giveXP


part.Touched:connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
	
game.Workspace.part:Destroy()

end
end)

4 answers

✓ Accepted answer

just create a script, and put here what you want happen when you touch the part, put the script between function OnTouched(Part) and script.Parent.Touched:connect(OnTouched)

function OnTouched(Part) 


end 

script.Parent.Touched:connect(OnTouched)

1 comment

0

FASCINATING. i just realized that functions can be connected and called with certain trigger events, so thanks for the help!

It's easy just use a touched event. Let's say I insert a Part in the workspace called.. "Part54". You can insert a script ANYWHERE in the game you want and just say:

game.Workspace.Part54.Touched:connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
game.Workspace.[YourPartName/In this case Part54]:Destroy()
end
end)


It's that easy, just identify the object in the workspace and add .Touched! I hope this helps bro! :D

EDIT:You can just put that script inside the box/Part you want. And then put the following script. What it will do is:

Line1:If that part gets touched... Line2:If the "Thing" that touched is Human/Player then... Line3:Destroy the part! Line4:End the function at line 2 Line5:End the function at line 1

8 comments

0

P.S. You can use this in other scripts such as game.Players.[LOCALPLAYER/PLAYERNAME].PlayerGui.TestGui.TestButton.MouseButton1Click:connect(function(). Don't forget the "end)"

0

Ok. Im just trying to make a box send a signal from its regular script to a local player script if the player ever touched it. Whoever touched the box first will recieve a signal, then the box proceeds to destroy itself. What do i put down, and where?

0

Where is the player's script at? In it's character?

0

its in StarterGui, as a local script

0

nvm

0

And you should put scripts in the StarterPlayer, not in the startergui. I changed the script. See if it works

0

now, how would i call a function within this that goes off for the player that touched it?

0

This is scripting helpers not writers. If you wanna be a good scripter you gotta learn. By the way, the answer is "Use a module script". Find more about them here: https://www.youtube.com/watch?v=qrulMMc0cNI . If I helped accept the answer! :D

function onTouch(Humaniod)

(Might work)

game.Players.LocalPlayer.Character.Touched:Connect(function() print('hi') end)

13 comments

0

where would i put this? in the character or in the part?

0

Oof i gooned i meant Character.Humanoid.Touched:() but also this will work as a local script in startergui or as a script as well as long as you replace localplayer w/ a name

0

i need something for inside a normal script. I simply want the box to broadcast a signal if a player has touched it. As of right now, the boxes spawn, but immediately disappear

0

oh well instead of humanoid you would do something like box.Touched:Connect(function(toucher) print(toucher.Name.." touched box") end)

0

but i need the toucher to be human only

0

if toucher.Parent:FindFirstChild("Humanoid") then --toucher is human end

0

Now how would i send a function signal to the player that touched it?

0

well that depends on what you want to do with that player

0

Well, to put it simply, i just want the box to trigger a function if a player touched that box. and the function will be in all players, but i want it to only go off to whoever touched the box first. Kinda like in Agar.io how you can touch the little circles, it will make you, and only you, grow

0

I mean you could make a remote event but you might not need one depending on what the function in each player does

0

i have a local script in every character that gives them 1 xp upon touching the box. The box is in ServerStorage and replicates. There is a normal script in the box, and i want the box to send a signal if it ever touches a player. (i might be able to put the signal thing inside the character itself, reversing it)

0

If the box touches a character, it will send a signal to whoever touched then proceed to destroy itself. Then, whoever recieved the signal will add 1 to a local variable. Thats it

0

You're turning things too complicated for just a box. Use a module script

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