Hello. I'm trying to make a game based on tornadoes, and I used particle effects to create a realistic looking tornado. The only downfall with this is that particle effects are only visible within a certain short distance. What I am trying to do is make the base part for the tornado visible to a specific player once they get to far to see the particle effects, and invisible again when they can be seen. I know that I would have to work with a local script to do this, but I can't figure out anything. Any ideas?
Put this in a local script in StarterPlayerScripts.
01 | local myself = game.Players.LocalPlayer |
02 | local distanceToSeeTornado = 100 --Change this to whatever distance. |
03 | local gameStarted = true --Putting this in if you wanted a minigame sorta game. Make sure to modify this variable and set it accordingly to your minigame setup. |
04 |
05 | while true do |
06 | if gameStarted then |
07 | local tornado = workspace:FindFirstChild( "TornadoPart" ) --Rename tornado part to whatever the base part is supposed to be named. |
08 | if myself:DistanceFromCharacter(tornado.Position) < = distanceToSeeTornado then |
09 | tornado.Transparency = 0 --Alternatively, you could replace 0 with 1 - (distanceToSeeTornado - myself:DistanceFromCharacter(tornado.Position))/100, though I'm not fully sure if that'll work. |
10 | else |
11 | tornado.Transparency = 1 |
12 | end |
13 | end |
14 | wait() |
15 | end |
If you don't need the minigame structure, just remove the gameStarted Variable and the 'if statement' used with it.
I have managed to create my own script. It still doesn't work, but maybe this could give a good start to anyone trying to answer.
01 | local funnel = script.Parent --Directory to base tornado part |
02 |
03 | game.Players.PlayerAdded:Connect( function (player) --Starts when a player joines the game |
04 | local Player = game:GetService( "Players" ).LocalPlayer.Name |
05 | local Character = workspace:FindFirstChild(Player) |
06 | while true do |
07 | if Character.UpperTorso then --Uses r15 characters |
08 | local magnitude = (Character.UpperTorso.Position - workspace.Tornado.Funnel.Position).Magnitude --Uses magnitude instead of "DistanceToPlayer" |
09 | if magnitude > 600 then --Distance I want tornado to be visible past |
10 | funnel.Transparency = 0 |
11 | else |
12 | funnel.Transparency = 1 |
13 | end |
14 | wait( 1 ) --There are lot's of other things going on, so secondly updating would be better |
15 | end |
16 | end |
17 | end ) |