Splash Script help

oh man 2 devforum posts for help in 2 days

Hello DevForum!
Today I’ve had troubles creating a splash script.
My original goal was to make a script that’s a child of a part, that can find the players position if the player touches the block (which I somehow cant get cancollide), it plays a particle effect and sound, just like how a splash works.

I have an invisible part that is walkthrough (i had a friend help me with it so its labeled).

    if hit.Name == "HumanoidRootPart" then -- makes sure the part name is humanoidrootpart
        local a = particle:Clone() --particle is the part with the splash effect
        a.Parent = workspace --Puts the particle into workspace so it can be visible
        a.CFrame = hit.CFrame -- Put the particle location at humanoidrootpart's location
        game:GetService("Debris"):AddItem(a,1) -- "1" is how many seconds before the particle is destroyed (you can change it if u want)
    end
    end

script.Parent.Touched:Connect(function(hit)```

If you need the model it is here : https://www.roblox.com/library/3534258347/grr

Thanks!
2 Likes

Sorry it took people 16 hours to give you a solution - relatively simple problem.

First observations:

  1. Incorrect grammar with the Connect. Also had to fake define particle just to make it not flag errors.

Method 1:

local particle = script.Parent.Particle

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		if hit.Name == "HumanoidRootPart" then	
			local a = particle:Clone()
			a.Parent = workspace
			a.po = hit.CFrame
			game:GetService("Debris"):AddItem(a,1)
		end
	end
end)

Method 2:

function touched(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		if hit.Name == "HumanoidRootPart" then	
			local a = particle:Clone()
			a.Parent = workspace
			a.po = hit.CFrame
			game:GetService("Debris"):AddItem(a,1)
		end
	end
end

script.Parent.Touched:Connect(touched)
  1. You’ve kind of used an inefficient method as it relies the HumanoidRootPart touching.

Here is mine and it works for me - what I’ve done is basically if a Player touches the water then whatever enters in makes a splash effect:

local Particle = script.Parent.Particle -- This is a brick with a Particle Emitter in it. The brick is anchored and it is cannot collide, it is also invisible.

function Touched(hit)
	print("touched", hit.Name)
	if hit.Parent:FindFirstChild("Humanoid") then
		if hit.Parent:FindFirstChild("HumanoidRootPart") then -- If the person is a player they should have this and a Humanoid part.
			local splash = Particle:Clone() -- Better naming, easier to understand.
			splash.Parent = script.Parent -- Set the parent to the script's parent so that way everything can be kept together nicely.
			splash.CFrame = hit.CFrame
			game:GetService("Debris"):AddItem(splash,1)
		end
	end
end

script.Parent.Touched:Connect(Touched) -- Connect my function to the event.

I’ll leave you to do the sounds etc, just reply if you need any help.

3 Likes

Sorry for the late reply, but this happened.

image

^ Tried with enabled and disabled and transparency 0 and 1, and I couldnt figure out how to get it to work, any idea?

Is the issue the amount of times its printing 'touched {NAME}?

If its to do with the “touched {NAME}” then trust me thats perfectly fine. If its anchored its going to touch these things once or twice and it shouldn’t lag your game so no need to worry. I’m saying that from experience as I’ve made weaponry discs which work in a game with tons of parts - it prints “touched” so many times and even I am like ‘how does it handle all this so fast’. Make sure the particle part is anchored else it will collide with everything it falls onto. It might also count objects it was touching when the game started as “touched” however I believe thats only if an unanchored object moves at all.

Additional question:

How does your particle system work out of curiosity?
Its just if I’m following your method: when you touch the part the entire part moves to the new location if it is a humanoid. Respectively imagine if this was a huge swimming pool - you could splash and have a huge new box (which wouldn’t matter but it would be invisible and large). Also if it does clone its parent then you can have a splash rebound effect if the script remains in the new particle. Hard to explain without demonstrating that tbh.

If this is the case I would personally use the zone and particle brick method which I demonstrated in mine - this isn’t because your method doesn’t work (it does) but its purely because then I’m not cloning my parent part and moving it and so it would eliminate any scripts being moved over - it also keeps the particle brick small. The little box which creates the particle as well would also be neater in studio as it could have its own respective name and you could store all the current splashes you have.

A few thoughts btw which might interest you:

Depending on how your particle effect works:
I found it cool how you used the debris service but I found myself that when it deletes the part the current particle effect goes from mid air to poofing out of existance. It wouldn’t matter to your average player who just wants to play your game and doesn’t always notice the finer detail but I honestly can get bothered about the little things - most people won’t notice though. I mean if you really wanted to you could actually map an accurate height of a splash using maths (I wouldn’t as its overkill) but you can just increment the height of the particle down as to make it seem like the water has fallen down but meh thats just depending on how your particle effect works.

You could also have a splashing arm effect if you wanted:
If you find the sweet spot when the arms are moving when you walk using the bounds created (arm will rotate and touch it causing the effect) it would actually seem like your running in the water and splashing.

  • Have to say though splashing is epic and I sometimes wonder how come people haven’t used it tons in roleplay games :laughing:
1 Like

The issue currently isn’t the printing, I’m pretty sure its simple but I’m just looking straight over it. So far I don’t have a particle system that works, but I’m hopefully getting there soon, but the way I wanted it to work was like, have a invisible block with a transparent or inactive ParticleEmitter that can find the location of a player where they are on the invisible block, and it enables the particleemitter or makes it visible, then either follows the player while they swim or just dissapears.

The error now is it saying “CFrame is not a valid member of ParticleEmitter”. I’ve guessed this has to do with the location because everywhere I step that’s the output, even when my particle isnt transparent or disabled.
Also I don’t think I said thank you last time, sorry.

Thank you.

Particle Emitters aren’t actually a part, they don’t have a position and they have to be placed in a part in order to have an effect. If you want an effect to appear then you have a part - then CFrame the part around so that it follows the user’s torso. You make the part invisible and turn collision off - looks like you’ve splashing in the water. Hence why having this:

local Particle = script.Parent.Particle -- This is a brick with a Particle Emitter in it. The brick is anchored and it is cannot collide, it is also invisible.

function Touched(hit)
	print("touched", hit.Name)
	if hit.Parent:FindFirstChild("Humanoid") then
		if hit.Parent:FindFirstChild("HumanoidRootPart") then -- If the person is a player they should have this and a Humanoid part.
			local splash = Particle:Clone() -- Better naming, easier to understand.
			splash.Parent = script.Parent -- Set the parent to the script's parent so that way everything can be kept together nicely.
			splash.CFrame = hit.CFrame
			game:GetService("Debris"):AddItem(splash,1)
		end
	end
end

script.Parent.Touched:Connect(Touched) -- Connect my function to the event.

Would suit your design. You can then place in the particle known as splash any effects and activate a local script (which can communicate with the server) to move the particle around if you wanted. You’d just fire a remote event at the client saying “Player” is splashing and then the server can handle the splashing - I’d explore your options though because I can think of hundreds of ways to make a splash system work it would just depend on how far I was going in terms of detail.

I am not sure how Touched:Connect() operates when trying to handle multiple clients - cause you could just do a while touching loop and operate splashing.

1 Like

Alright I understand most of it after reading over a couple times, but I have a couple small questions.

Would I change any properties of the particleemitter besides the particle decal itself to make the splash work?
and
Would the script be a child of the workspace or the part, or something else?

Responses:

  1. Two ways you can change the particles, a lot of it is over time.
Splashing with over complicated maths

I laughed when I made this LOL

s = ut + 1/2at^2
v = u + at

s = displacement
u = initial velocity
v = final velocity (velocity at the time)
a = acceleration
t = time

  • lifetime - s
  • rate - value - t
  • speed - measured upon impact velocity and should be determined using the s = ut + 1/2at^2 equation.
  • spread angle - would be dependent impact.
Normal Splashing

Over 10 seconds?

  • lifetime - For the first 5 seconds, increase this and then for the last 5 decrease this.
  • rate - 10 subtract the time in seconds.
  • speed - v
  • spread angle - ROBLOXians can only really fall into things upwards so you’ll be fine.
  1. If your doing the place a script into a player type thing then you can just place the local script in the Player.Backpack and then save the splash in the Player’s folder in the workspace if you wanted to. Alternatively you could make a folder called splashes and it could search up “Player.Name…'s Splash” and move it to the new humanoid root location - your choice really. The local script would simply be a remote event trigger signalling movement in the character (and thus on the servers side it will handle the splash effect accordingly).
1 Like