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

How to detect when a player has touched terrain(Water)?

I have a timer Gui for my Ninja Warrior game, and here are the components:

  • A Part called Start to start the timer

  • A Part called ClearButton to finish the course and disable the timer(overlap debug)

  • A Part called Reset to reset the timer Gui and enable it for Start to be clicked

Here are the scripts (they do all work and if you correct me you will be wrong):

Start Script:

script.Parent.ClickDetector.MouseClick:Connect(function()
	for i = 100, 0, -1 do
		for _,p in pairs(game.Players:GetPlayers()) do
			p.PlayerGui.ScreenGui.TextLabel.Text = ""..i.." seconds"
			wait(1)
		end
		if i == 0 then
			for _,k in pairs(game.Players:GetPlayers()) do
				k.PlayerGui.ScreenGui.TextLabel.Text = "Failure!"
			end
			game.Workspace.ClearButton.Script.Disabled = true -- Prevents the player from clearing after they have failed
		end
	end
end)

ClearButton Script:

s = Instance.new("Sound")
s.Parent = script.Parent -- Set the Sound Parent to the ClearButton
s.SoundId = "rbxassetid://139437388"
s.Volume = 1
s.Looped = false
script.Parent.ClickDetector.MouseClick:Connect(function()
	s:Play()
	for _,v in pairs(game.Players:GetPlayers()) do
		v.PlayerGui.ScreenGui.TextLabel.Text = "Clear!"
	end
	game.Workspace.Start.Script.Disabled = true -- Disable the timer
end)

Reset Script:

script.Parent.ClickDetector.MouseClick:Connect(function()
	if game.Workspace.Start.Script.Disabled == true then -- If the timer is disabled...
		game.Workspace.Start.Script.Disabled = false -- Enable it
		for _,v in pairs(game.Players:GetPlayers()) do
			v.PlayerGui.ScreenGui.TextLabel.Text = "Timer enabled" -- Verification msg
		end
	end
end)

Now suppose that, in the script belonging to Start, I want to detect if a player has touched terrain, specifically water. I've tried everything I know and I can't seem to get it. How would you detect if a player has touched terrain? An example would be nice.

1 comment

0

I don't know how to detect if you touch terrain but can't you check for the swimming humanoid state?

4 answers

✓ Accepted answer
if hit:IsA("Terrain")  then

sorta thing

But for water you replace Terrain with "Water"

I dont know if its possible or not, (I am not that smart maybe its possible) but, you could use for example, a brick. Put the brick over the water, mess with it via script and make in invisible and set can collide off. Would work 100%. I know its not really what you want but, eh still works I guess. Hope its good enough for you! Good Luck with your game btw.

6 comments

0

I'm talking about terrain, not a Part. Try again.

0

Thats what I meant, I dont know if its possible to be honest. I dont know. Just an idea that you could use. Dont be rude.

0

I know how to detect when they hit a part, but not terrain. Parts are easy.

0

Clever! Will keep your idea in mind when I play around with terrains. Thanks.

0

MCAndRobloxUnited, I just gave you an idea because I dont know how to detect if a player touches a terrain. Stop being rude.

0

lol he said "Try again", just like if his post was a riddle

Haven't done this before but I have an idea.

Put this in the Character's Torso/Legs.

script.Parent.Touched:connect(function(hit)
	print(hit.ClassName)
end)

This is to check if the 'water' has a separate ClassName other than 'Terrain'. If it does have it's own ClassName, you can go on from there like if hit:IsA('Water') then ..

2 comments

0

If this doesn't work try print(hit.Name)

0

Since legs are attached to the torso in a player, it will print the torso aswell, so you will need to add a filter in your code.

It's possible:

https://www.roblox.com/games/913673244/Goose-Haven-Teaser?rbxp=264859050

The terrain touched stopped working for me some time ago, and I made a much better implementation.

You must first create a region at the target location, then check for the voxels in that region what material type they are. It's kinda complicated and hard to make error free, but as you see a decent implementation is possible.

Good luck!

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