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):
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)
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)
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.
if hit:IsA("Terrain") then
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.
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 ..
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.