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

How do you make a script go off after touching an object?

So I wanted to make a thing where after reaching a certain spot new objects will appear, I manage to do one bit but it only does it when you join the game, and I would like it to appear after touching a certain part not when you join the game.

2 answers

If its 1 part then this will be the code:

Local trigger = [Locate your trigger here]
trigger.Touched:Connect(function(h) -- This will start the function whenever its touched!
if game.Players:GetPlayerFromCharacter(h.Parent) then -- This will make sure its actually a player thats triggered it, rather then something else.
-- Your code here
end
end

If you require to run any code on the character, use h.Parent - This should return the character. If its a model, create a sort of hit box on the floor. Put that as the trigger.

1 comment

0

Should probably mention debouncing as well so it doesn't trigger the event multiple times due to animations/slight clipping.

I recommend using .hit like

script.Parent.Touched:Connect(function(hit) if hit.Parent:FindFirstChild ('Humanoid') then if hit.Parent:FindFirstChild ('Humanoid').Health ~= 0 then local player = game.Players:GetPlayerFromCharacter(hit.Parent) game.ReplicatedStorage.Remotes.OpenPetShop:FireClient(player) end end end)

is what I used

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