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

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

Asked by 6 years ago

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.

0
I don't know how to detect if you touch terrain but can't you check for the swimming humanoid state? User#20388 0 — 6y

4 answers

Log in to vote
0
Answered by 6 years ago
if hit:IsA("Terrain")  then

sorta thing

But for water you replace Terrain with "Water"

Ad
Log in to vote
1
Answered by 6 years ago
Edited 6 years ago

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.

0
I'm talking about terrain, not a Part. Try again. DeceptiveCaster 3761 — 6y
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. HeyItzDanniee 252 — 6y
0
I know how to detect when they hit a part, but not terrain. Parts are easy. DeceptiveCaster 3761 — 6y
0
Clever! Will keep your idea in mind when I play around with terrains. Thanks. Le_Teapots 913 — 6y
View all comments (2 more)
0
MCAndRobloxUnited, I just gave you an idea because I dont know how to detect if a player touches a terrain. Stop being rude. HeyItzDanniee 252 — 6y
0
lol he said "Try again", just like if his post was a riddle TheRealPotatoChips 793 — 4y
Log in to vote
0
Answered by
hellmatic 1523 Moderation Voter
6 years ago

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 ..

0
If this doesn't work try print(hit.Name) hellmatic 1523 — 6y
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. Le_Teapots 913 — 6y
Log in to vote
0
Answered by
Nonaz_jr 439 Moderation Voter
6 years ago

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!

Answer this question