Basic splash script

Hello! Today I will be providing a royalty free script that will make it so whenever a player hops in the water the water will splash creating a basic example of floating and buoyancy in code for a player.

Here is the code hope you enjoy!

-- This script creates a temporary splash effect whenever a player touches the water part.

-- Store the water part (the part this script is inside of)
local water = script.Parent

-- Function triggered when any object touches the water
local function onTouched(hit)
    -- 'hit' is the part that touched the water (could be a limb, tool, object, etc.)

    -- Try to get the Character model from the touching part
    local character = hit.Parent
    
    -- Check if the Character belongs to a real Player
    local player = game.Players:GetPlayerFromCharacter(character)

    -- Only continue if a real player touched the water
    if player then
        
        -- Create a ParticleEmitter (this makes visual effects)
        local splash = Instance.new("ParticleEmitter")

        -- Image used for each splash particle
        splash.Texture = "rbxassetid://242431182"

        -- How long each particle stays visible
        splash.Lifetime = NumberRange.new(0.5)

        -- Speed at which particles fly outward
        splash.Speed = NumberRange.new(5, 10)

        -- How many particles are released per second
        splash.Rate = 200

        -- Attach the emitter to the water so it appears at the right place
        splash.Parent = water

        -- After 0.4 seconds, turn off and remove the splash effect
        task.delay(0.4, function()
            splash.Enabled = false   -- Stop creating new particles
            task.wait(1)             -- Allow remaining particles to fade
            splash:Destroy()         -- Remove it entirely from the world
        end)
    end
end

-- Connect the 'Touched' event of the water part to the onTouched function
-- This means the code runs every time something touches the water
water.Touched:Connect(onTouched)

3 Likes