Ad
Log in to vote
0

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

Asked by 4 days ago
Edited 4 days 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)

Hi.

Looks like you're using an ad blocker.

That's fine...

No, it really is.

Just, I mean, we put a lot of work into this site, you know?

It would be really really appreciated if you would turn off your ad blocker for our website...

We tried really hard to make our ads as unobtrusive as possible.

If you really hate ads, would you consider a $2 donation via Patreon?

Here's the link.

We love you. We hope you love us too.

.

..

...

Now back to your regularly scheduled Scripting Helpers....

...

..

.

3 answers

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

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

0
where would i put this? in the character or in the part? SweetAsCreampie 34 — 4d
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 17 — 4d
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 SweetAsCreampie 34 — 4d
0
oh well instead of humanoid you would do something like box.Touched:Connect(function(toucher) print(toucher.Name.." touched box") end) Vulkarin 17 — 4d
View all comments (9 more)
0
but i need the toucher to be human only SweetAsCreampie 34 — 4d
0
if toucher.Parent:FindFirstChild("Humanoid") then --toucher is human end Vulkarin 17 — 4d
0
Now how would i send a function signal to the player that touched it? SweetAsCreampie 34 — 4d
0
well that depends on what you want to do with that player Vulkarin 17 — 4d
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 SweetAsCreampie 34 — 4d
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 17 — 4d
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) SweetAsCreampie 34 — 4d
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 SweetAsCreampie 34 — 4d
0
You're turning things too complicated for just a box. Use a module script wilsonsilva007 78 — 3d

Answer this question



Ad