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

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

Asked by 7 years ago
Edited 7 years ago

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

Log in to vote
0
Answered by 7 years ago

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)
0
FASCINATING. i just realized that functions can be connected and called with certain trigger events, so thanks for the help! User#19492 0 — 5y
Ad
Log in to vote
1
Answered by 7 years ago
Edited 7 years ago

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

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)" wilsonsilva007 373 — 7y
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? User#19492 0 — 7y
0
Where is the player's script at? In it's character? wilsonsilva007 373 — 7y
0
its in StarterGui, as a local script User#19492 0 — 7y
View all comments (4 more)
0
nvm wilsonsilva007 373 — 7y
0
And you should put scripts in the StarterPlayer, not in the startergui. I changed the script. See if it works wilsonsilva007 373 — 7y
0
now, how would i call a function within this that goes off for the player that touched it? User#19492 0 — 7y
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 wilsonsilva007 373 — 7y
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago
function onTouch(Humaniod)

(Might work)

Log in to vote
-1
Answered by
Vulkarin 581 Moderation Voter
7 years ago

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

0
where would i put this? in the character or in the part? User#19492 0 — 7y
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 Vulkarin 581 — 7y
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 User#19492 0 — 7y
0
oh well instead of humanoid you would do something like box.Touched:Connect(function(toucher) print(toucher.Name.." touched box") end) Vulkarin 581 — 7y
View all comments (9 more)
0
but i need the toucher to be human only User#19492 0 — 7y
0
if toucher.Parent:FindFirstChild("Humanoid") then --toucher is human end Vulkarin 581 — 7y
0
Now how would i send a function signal to the player that touched it? User#19492 0 — 7y
0
well that depends on what you want to do with that player Vulkarin 581 — 7y
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 User#19492 0 — 7y
0
I mean you could make a remote event but you might not need one depending on what the function in each player does Vulkarin 581 — 7y
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) User#19492 0 — 7y
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 User#19492 0 — 7y
0
You're turning things too complicated for just a box. Use a module script wilsonsilva007 373 — 7y

Answer this question