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

[EDIT AT BOTTOM]Detecting when a player is in the shade(under a tree or in a house)?[solved]

Asked by
soutpansa 120
7 years ago
Edited by M39a9am3R 7 years ago

Before I start, let me make it clear that I am not asking someone to write me a script, instead I am asking if anyone knows a method or someplace to start trying to figure this out.

In a game I'm working on, players can become a vampire, during the day time, vampires will burn and eventually die. To detect when a vampire is in the shade during the day time, I have taken a transparent block that if a player touches, they will not die, and if they leave the block, they will die. Here is the code to that:


function OnTouched(Part) local h = Part.Parent:findFirstChild("Humanoid") if (h~=nil) then local thisplr = game.Players:findFirstChild(h.Parent.Name) if (thisplr~=nil) then local Data = thisplr:findFirstChild("NonSave") Data.InSun.Value = 0 end end end function OnLeave(Part) local h = Part.Parent:findFirstChild("Humanoid") if (h~=nil) then local thisplr = game.Players:findFirstChild(h.Parent.Name) if (thisplr~=nil) then local Data = thisplr:findFirstChild("NonSave") Data.InSun.Value = 1 end end end script.Parent.Touched:Connect(OnTouched)

(if InSun == 1, the player will be set on fire and killed. The script that does that is in the StarterPack)

This looks good on paper, but when you start to consider the problems with this method, you notice that: A: if the player is in a house with hall ways or something similar, there will have to be more than one of these blocks placed in the house, but if you leave the block, even if you're touching another block that changes the value to 0, you will still be set on fire and killed.

B: Due to the way roblox is, it can sometimes detect that you left the brick even though you didn't.

On to my question, I have another method that if doable, should work ok. Maybe you can detect if a certain brick is above the player's head or something.

But I still have no clue how to even start figuring this out, and people that I've asked had no idea where to start either. So could someone please point me in the correct direction? Don't write me a script, but maybe give me a link to a wiki page that could be helpful, because I don't even know what to search for when trying to figure this out.

Thanks for reading my novel long question.

EDIT: So, the way me and a friend found out is that we use a ray that is really high up.

0
Edited title to properly display answered icon on questions page. Please make sure [solved] is amended to the end of your question title in lowercase letters for the question to be indicated as answered by the asker. M39a9am3R 3210 — 7y

Answer this question